Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone MPNowPlayingFoCenter defaultCenter不会更新或检索信息_Iphone_Ios_Mpmovieplayercontroller - Fatal编程技术网

Iphone MPNowPlayingFoCenter defaultCenter不会更新或检索信息

Iphone MPNowPlayingFoCenter defaultCenter不会更新或检索信息,iphone,ios,mpmovieplayercontroller,Iphone,Ios,Mpmovieplayercontroller,我正在努力更新MPNowPlayingFoCenter,但遇到了一些问题。我已经试了很多次了,现在我不知所措。以下是我的代码: self.audioPlayer.allowsAirPlay = NO; Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter"); if (playingInfoCenter) { NSMutableDictionary *songInfo

我正在努力更新MPNowPlayingFoCenter,但遇到了一些问题。我已经试了很多次了,现在我不知所措。以下是我的代码:

    self.audioPlayer.allowsAirPlay = NO;

    Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");

    if (playingInfoCenter) {

        NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];

        MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:@"series_placeholder"]];

        [songInfo setObject:thePodcast.title forKey:MPMediaItemPropertyTitle];
        [songInfo setObject:thePodcast.author forKey:MPMediaItemPropertyArtist];
        [songInfo setObject:@"NCC" forKey:MPMediaItemPropertyAlbumTitle];
        [songInfo setObject:albumArt forKey:MPMediaItemPropertyArtwork];

        [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];


    }
这不起作用,我也试过:

   [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:nil];
试图让它从iPod应用程序中删除现有信息(或任何可能包含信息的内容)。此外,为了看看是否能找出问题所在,我已尝试检索应用程序发布的当前信息:

  NSDictionary *info = [[MPNowPlayingInfoCenter defaultCenter] nowPlayingInfo];
  NSString *title = [info valueForKey:MPMediaItemPropertyTitle];
  NSString *author = [info valueForKey:MPMediaItemPropertyArtist];

  NSLog(@"Currently playing: %@ // %@", title, author);
我现在正在玩:(空)/(空)

我已经对此进行了很多研究,下面的文章对其进行了非常透彻的解释,但是,我仍然无法使其正常工作。我错过什么了吗?会有什么干扰吗?这是我的应用程序需要注册才能访问的服务吗(在任何文档中都没有看到)


我使用下面的代码,它总是有效的。我也像你一样使用MPMoviePlayer。您是否检查过
NSClassFromString(@“mpnowplayingfocenter”)
是否实际返回
YES
?您是否在plist中设置了app play audio in background键

- (void) loadMPInformation
{
    NSDictionary *mpInfo;

    if([savedTrack.belongingAlbum.hasAlbumArt boolValue] == NO){
        mpInfo = [NSDictionary dictionaryWithObjectsAndKeys:savedTrack.belongingAlbum.album, MPMediaItemPropertyAlbumTitle, 
                  savedTrack.belongingArtist.artist, MPMediaItemPropertyArtist, savedTrack.name, MPMediaItemPropertyTitle, nil];   
    } else {
        UIImage *artImage = [UIImage imageWithData:savedTrack.belongingAlbum.art];
        MPMediaItemArtwork *artwork = [[MPMediaItemArtwork alloc] initWithImage:artImage];
        mpInfo = [NSDictionary dictionaryWithObjectsAndKeys:savedTrack.belongingAlbum.album, MPMediaItemPropertyAlbumTitle, 
                  savedTrack.belongingArtist.artist, MPMediaItemPropertyArtist, savedTrack.name, MPMediaItemPropertyTitle, artwork, MPMediaItemPropertyArtwork, nil];
    }
    [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = mpInfo;

}

我最终解决了问题,我没有提示我的应用程序接收远程控制事件,只是添加了这一行修复了问题:

 [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

执行此代码时是否播放媒体?我尝试过音频播放(通过MPMoviePlayer),但没有使用相同的结果使用nslog打印[MPNowPlayingFoCenter defaultCenter]。在文档中,他们说:默认的now playing信息中心保存指定为远程控制事件接收器的应用程序的now playing信息。您正在某个远程设备上播放媒体吗?确保媒体正在某些远程设备上播放。因为文档中说:远程控制事件允许用户通过系统传输控件或外部附件控制应用程序多媒体。当我打印MPNowPlayingFocenter时,我得到:我没有在远程设备或附件上播放。。。我的理解是,您可以通过在设备上播放音频来更新此信息(如锁屏上显示的),但它也可以用于远程设备…是的,我已检查它是否返回“是”,我还设置了应用程序在plist中播放音频…等等。你在设备或模拟器上试过吗?因为我注意到它在模拟器中不起作用。我只是在设备上试过。。。你必须注册才能收到播放/暂停按钮的通知吗?我注册了。但我不记得这是必要的——尽管尝试是件好事。另外,我记得
mpnowplayingfocenter
非常挑剔,你发送的任何字符串都不是零,一定要测试一下。是的,没有一个字符串是零。我面临类似的问题。即使我实现了上述所有方法,我也不会接收控制事件。