gpt4 book ai didi

ios - MPNowPlayingInfoCenter 和 MPRemoteCommandCenter 在模拟器中工作,但在设备上不工作

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:41:58 26 4
gpt4 key购买 nike

我正在将 MPNowPlayingInfoCenter 集成到音乐播放应用中。当我在 iOS 模拟器中运行它时,它与 MPRemoteCommandCenter 的集成工作得很好。当我在设备上运行相同的代码时,控制中心中的音乐控件根本不会改变。就好像应用程序没有向 MPNow 和 MPRemote 中心注册事件。

MPNowPlayingInfoCenter *np = [MPNowPlayingInfoCenter defaultCenter];

np.nowPlayingInfo = @{MPMediaItemPropertyTitle:[tracks objectAtIndex:self.currentTrack],
MPMediaItemPropertyArtist:currentArtist,
MPMediaItemPropertyAlbumTitle:currentAlbum,
MPMediaItemPropertyMediaType:@(MPMediaTypeMusic),
MPMediaItemPropertyPlaybackDuration:@(self.audioHandler.audioDuration),
MPNowPlayingInfoPropertyElapsedPlaybackTime:@(self.audioHandler.position),
MPNowPlayingInfoPropertyPlaybackRate:rate
};

我的 View Controller 生命周期方法中有所有这些好东西:

- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

[self becomeFirstResponder];
}

- (void)viewWillDisappear:(BOOL)animated {

// Turn off remote control event delivery
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];

// Resign as first responder
[self resignFirstResponder];

[super viewWillDisappear:animated];
}
- (BOOL)canBecomeFirstResponder {
return YES;
}

一些注意事项:

  1. 我没有使用 AVPlayer。我正在使用 CoreAudio/Audio 单元播放音频。应用程序的这一部分运行良好。
  2. 我仅在 iOS 7 和 iOS 8 上进行测试。
  3. 我正在使用 Amazing Audio Engine 作为 CoreAudio 包装器:http://theamazingaudioengine.com

最佳答案

找到了。在初始化令人惊叹的音频引擎(顺便说一下,这是一个很棒的框架)时,如果有人想使用 MPNowPlayingInfoCenter,则需要告诉框架它不想与其他应用程序共享音频输出。为此我做了:

self.audioController = [[AEAudioController alloc]
initWithAudioDescription:[AEAudioController nonInterleaved16BitStereoAudioDescription]
inputEnabled:NO];
self.audioController.allowMixingWithOtherApps = NO;

关于ios - MPNowPlayingInfoCenter 和 MPRemoteCommandCenter 在模拟器中工作,但在设备上不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26578474/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com