锁定屏幕上的AVAudioPlayer [英] AVAudioPlayer on Lock Screen

查看:147
本文介绍了锁定屏幕上的AVAudioPlayer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 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.
        }

}

所以问题:


  1. 为了让事情正常,我是否应该实施这两种子类型?

  1. In order to have things work right, am I supposed to implement those two subtypes, too?

此方法仅启用倒带播放/暂停快进按钮,但它不显示文件标题,图稿和持续时间。如何使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆