【问题标题】:MPMoviePlayerController stops iPod music playbackMPMoviePlayerController 停止 iPod 音乐播放
【发布时间】:2012-11-20 04:40:41
【问题描述】:

在我的应用程序中,我使用 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];

【问题讨论】:

    标签: iphone ios mpmovieplayercontroller


    【解决方案1】:

    詹姆斯先生。当我从我的应用程序播放音频文件时,我也遇到了这个问题。 I was worked on AVAudioPlayer to play song from my application。当我从我的应用程序播放歌曲时,如果 iPod 播放歌曲已停止并且不再暂停或播放。所以我在我的应用程序中使用了下面的代码,它很有魅力。

    我不知道这会解决你的问题。试试这个,让我知道你的 cmets。

     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];
            }
    
        }
    } 
    

    请试试这个,让我知道你的 cmets。谢谢。一切顺利。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-25
      相关资源
      最近更新 更多