I'm currently trying to play music from the local iPod library using AVPlayer, not MPMusicPlayerController using the application controller.
I can get him to select a track from the local iPod lib and MPMediaQuery, but when I try to play the sound at a lower level using AVMutableAudioMixInputParameters, it doesn't seem to lower the volume at all.
The reason I use AVPlayer rather than MPMusicPlayerController is because I play some other sound in the background at the same time, and MPMusicPlayerController cannot play as an existing audio file using AVPlayer. The code that I have at the moment is:
MPMediaQuery *everything = [[MPMediaQuery alloc] init];
NSArray *itemsFromGenericQuery = [everything items];
MPMediaItem *song;
NSMutableArray *array = [[NSMutableArray alloc] init];
for (song in itemsFromGenericQuery)
{
[array addObject:song];
}
, .
, AVPlayer:
MPMediaItem *song = [array objectAtIndex:0];
NSURL *assetURL = [song valueForProperty:MPMediaItemPropertyAssetURL];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:assetURL options:nil];
NSArray *audioTracks = [asset tracksWithMediaType:AVMediaTypeAudio];
AVAssetTrack *track = [audioTracks objectAtIndex:0];
NSMutableArray *allAudioParams = [NSMutableArray array];
AVMutableAudioMixInputParameters *audioInputParams =
[AVMutableAudioMixInputParameters audioMixInputParameters];
[audioInputParams setVolume:0.3 atTime:kCMTimeZero];
[audioInputParams setTrackID:[track trackID]];
[allAudioParams addObject:audioInputParams];
AVMutableAudioMix *audioZeroMix = [AVMutableAudioMix audioMix];
[audioZeroMix setInputParameters:allAudioParams];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];
[playerItem setAudioMix:audioZeroMix];
[playerItem seekToTime:CMTimeMake(30, 1)];
[self setLocalPlayer:[AVPlayer playerWithPlayerItem:playerItem]];
[localPlayer play];
, AVPlayer URL- (); .
, ; . , , .
!
.