【问题标题】:mpmovieplayercontroller load new audio url from backgroundmpmovieplayercontroller 从后台加载新的音频 url
【发布时间】:2012-12-20 03:29:28
【问题描述】:

我有一个 MPMoviePLayerController,它可以从解析为数组的 xml 播放列表中连续 http 流式传输音频文件。

问题是在播放歌曲时,手机被锁定,它继续播放歌曲,支持背景音频等等,直到歌曲结束...... 但打电话时:

- (void) moviePlayBackDidFinish:(NSNotification*)notification {...}

然后我调用函数来加载下一首曲目

- (void) LoadTrack:(int)indexToPlay {

    //use the generic APIContentObject.
    APIContentObject *currentTrack = [playlist objectAtIndex:indexToPlay];
    NSLog(@"%@",[currentTrack SluggedURL]);

    //get url
    NSURL *url=[NSURL URLWithString:[currentTrack FileURL]];

    //moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
    if (!moviePlayer){

        moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];

    }else{

        //moviePlayer = nil;
        //moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];

        //moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
        //[moviePlayer initWithContentURL:url];
        [moviePlayer setContentURL:url];        
        moviePlayer.shouldAutoplay = YES;
        [moviePlayer prepareToPlay];
        [moviePlayer play];
    }
    ...

它不加载曲目并在输出中给我以下内容:

[MPCloudAssetDownloadController] Prioritization requested for media item ID: 0

正如您在注释行中看到的那样,我尝试了多种方法来解决这个问题。其中没有一个真正播放下一首歌。 是因为背景音频需要恒定流吗? 我不能这样吗?

我们有一个 CMS,用户可以在其中更改他们的播放列表,因此它需要在后台连接 mp3->-mp3。

播放当前歌曲很好,但为什么不加载新歌曲?

或者网络请求不被视为“背景音频”的一部分?

非常感谢。

【问题讨论】:

    标签: mpmovieplayercontroller


    【解决方案1】:

    我终于意识到我无法在后台启动任何新的 URL 连接。 我需要切换到 m3u 风格的播放列表并使用点播媒体服务器来完成我想做的事情。

    【讨论】:

      【解决方案2】:

      确保将 info.plist 文件中的 UIBackgroundModes 键设置为“音频”。 这将允许您的应用在后台仍执行代码。

      这里的文档以防万一。 链接:Check this link and scroll to: "Declaring Your App’s Supported Background Tasks"

      我在使用 mpmovieplayercontroller 时遇到了自己的问题,在寻求帮助时我找到了您的帖子。

      我目前正在使用 mpmovieplayercontroller 播放音频,当歌曲结束 (moviePlayBackDidFinish) 时,我向服务器询问下一首歌曲的 url。然后播放那首歌..冲洗并重复。当屏幕被锁定时它工作正常(这意味着它正在在应用程序处于后台并且屏幕被锁定时启动一个 url 连接)。

      【讨论】:

        猜你喜欢
        • 2013-03-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-02-16
        • 1970-01-01
        • 1970-01-01
        • 2013-12-04
        相关资源
        最近更新 更多