锁定屏幕上的AVAudioPlayer [英] AVAudioPlayer on Lock Screen
问题描述
我使用 AVAudioPlayer
(不是 AVPlayer
的)。我可以使用以下方法处理远程控制事件。到目前为止它工作得很好,但我看到这些事件还有两个子类型
: UIEventSubtypeRemoteControlEndSeekingForward
和 UIEventSubtypeRemoteControlEndSeekingBackward
。
- (void)remoteControlReceivedWithEvent:(UIEvent *)event {
//if it is a remote control event handle it correctly
if (event.type == UIEventTypeRemoteControl)
{
if (event.subtype == UIEventSubtypeRemoteControlPlay)
{
[self playAudio];
}
else if (event.subtype == UIEventSubtypeRemoteControlPause)
{
[self pauseAudio];
}
else if (event.subtype == UIEventSubtypeRemoteControlTogglePlayPause)
{
[self togglePlayPause];
}
else if (event.subtype == UIEventSubtypeRemoteControlBeginSeekingBackward)
{
[self rewindTheAudio]; //this method rewinds the audio by 15 seconds.
}
else if (event.subtype == UIEventSubtypeRemoteControlBeginSeekingForward)
{
[self fastForwardTheAudio]; //this method fast-forwards the audio by 15 seconds.
}
}
所以问题:
-
为了让事情正常,我是否应该实施这两种子类型?
In order to have things work right, am I supposed to implement those two subtypes, too?
此方法仅启用倒带
,播放/暂停$ c $锁定屏幕上的c>和
快进
按钮,但它不显示文件标题,图稿和持续时间。如何使用 AVAudioPlayer
或 AVAudioSession
显示该信息(我真的不想再有一个库/ API来实现这个)?
This method only enables the rewind
, play/pause
, and fast forward
buttons on lock screen, but it doesn't display the file title, artwork, and duration. How can I display that info using AVAudioPlayer
or AVAudioSession
(I don't really want one more library/API to implement this)?
2-a。我在搜索时发现了 MPNowPlayingInfoCenter
,但我对此并不了解。我是否必须使用它来实现上述内容? : - [
2-a. I discovered MPNowPlayingInfoCenter
while searching and I don't know much about it. Do I have to use it to implement those stuff above? :-[
推荐答案
你是对的, MPNowPlayingInfoCenter
是唯一的方法。所以继续并与 MediaPlayer.framework
链接。在处理播放曲目的类中,导入< MediaPlayer / MediaPlayer.h>
。每当您的曲目更改时,请执行以下操作:
You are correct, MPNowPlayingInfoCenter
is the only way to do this. So go ahead and link with MediaPlayer.framework
. In the class that handles playing tracks, import <MediaPlayer/MediaPlayer.h>
. Whenever your track changes, do this:
NSDictionary *info = @{ MPMediaItemPropertyArtist: artistName,
MPMediaItemPropertyAlbumTitle: albumName,
MPMediaItemPropertyTitle: songName };
[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = info;
这篇关于锁定屏幕上的AVAudioPlayer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!