Created
April 24, 2012 11:42
-
-
Save manmal/2478975 to your computer and use it in GitHub Desktop.
AVPlayer URL & volume Additions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "AVPlayer+MOAdditions.h" | |
#include <CoreMedia/CMBase.h> | |
#import "AVPlayerItem+MOAdditions.h" | |
@implementation AVPlayer (MOAdditions) | |
- (NSURL *)currentURL { | |
AVAsset *asset = self.currentItem.asset; | |
if ([asset isMemberOfClass:[AVURLAsset class]]) | |
return ((AVURLAsset *)asset).URL; | |
return nil; | |
} | |
- (void)setVolume:(CGFloat)volume { | |
NSArray *audioTracks = [self.currentItem.asset tracksWithMediaType:AVMediaTypeAudio]; | |
NSMutableArray *allAudioParams = [NSMutableArray array]; | |
for (AVAssetTrack *track in audioTracks) { | |
AVMutableAudioMixInputParameters *audioInputParams = [AVMutableAudioMixInputParameters audioMixInputParameters]; | |
[audioInputParams setVolume:volume atTime:kCMTimeZero]; | |
[audioInputParams setTrackID:[track trackID]]; | |
[allAudioParams addObject:audioInputParams]; | |
} | |
AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix]; | |
[audioMix setInputParameters:allAudioParams]; | |
[self.currentItem setAudioMix:audioMix]; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "AVPlayer+MOAdditions.h" | |
#include <CoreMedia/CMBase.h> | |
@implementation AVPlayer (MOAdditions) | |
- (NSURL *)currentURL { | |
AVAsset *asset = self.currentItem.asset; | |
if ([asset isMemberOfClass:[AVURLAsset class]]) | |
return ((AVURLAsset *)asset).URL; | |
return nil; | |
} | |
- (void)setVolume:(CGFloat)volume { | |
NSArray *audioTracks = [self.currentItem.asset tracksWithMediaType:AVMediaTypeAudio]; | |
NSMutableArray *allAudioParams = [NSMutableArray array]; | |
for (AVAssetTrack *track in audioTracks) { | |
AVMutableAudioMixInputParameters *audioInputParams = [AVMutableAudioMixInputParameters audioMixInputParameters]; | |
[audioInputParams setVolume:volume atTime:kCMTimeZero]; | |
[audioInputParams setTrackID:[track trackID]]; | |
[allAudioParams addObject:audioInputParams]; | |
} | |
AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix]; | |
[audioMix setInputParameters:allAudioParams]; | |
[self.currentItem setAudioMix:audioMix]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This won't work for live streaming. My
tracks
array is always empty...