0

私のアプリでは、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];
4

1 に答える 1

2

ジェームスさん。アプリからオーディオファイルを再生するときにも、この問題に直面しています。I was worked on AVAudioPlayer to play song from my application. iPodが曲を再生している場合、アプリから曲を再生すると停止し、一時停止または再度再生されることはありませんでした。だから私は自分のアプリで以下のコードを使用しましたが、それは魅力的です。

これで問題が解決するかどうかはわかりません。これを試して、あなたのコメントを教えてください。

 musicPlayer = [MPMusicPlayerController iPodMusicPlayer];
 if (musicPlayer.playbackState == MPMusicPlaybackStatePlaying) 
  {
       NSLog(@"Music Playing now");
       musicPlayerPaused = YES; //BOOL
       [musicPlayer pause]; // Here am pausing the iPod Music from here..
  } 

 // Playing the message sound here using the AVAudioPlayer...
 [sendMessageSound play];

AVAudioPlayerデリゲートでは、再び iPodMusic を再開しています

-(void) audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
    if (flag == YES) 
    {
        // IF the iPod song paused by us... we have to play it again after our Sound plays successfully...
        if (musicPlayerPaused == YES) 
        {
            musicPlayerPaused = NO;
            [musicPlayer play];
        }

    }
} 

これを試して、あなたのコメントを教えてください。ありがとう。ではごきげんよう。

于 2012-11-20T05:34:45.370 に答える