在我的应用程序中,我使用 MPMoviePlayerController 在屏幕上播放循环视频,并使用 MPMusicPlayerController 播放音乐。当我开始播放视频时,音乐停止。我不确定我做错了什么。我尝试在我的应用程序委托中设置 AudioSesion,但它似乎不起作用。
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: nil];
这是我的代码:
self.musicPlayer = [MPMusicPlayerController iPodMusicPlayer];
MPMediaQuery* query = [MPMediaQuery songsQuery];
[query addFilterPredicate:[MPMediaPropertyPredicate predicateWithValue:@"Lost" forProperty:MPMediaItemPropertyTitle comparisonType:MPMediaPredicateComparisonEqualTo]];
[query setGroupingType:MPMediaGroupingAlbum];
//Pass the query to the player
[self.musicPlayer setQueueWithQuery:query];
[self.musicPlayer play];
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"movie" ofType:@"mp4"];
NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
// Play the movie.
[self.moviePlayer setRepeatMode:MPMovieRepeatModeOne];