【问题标题】:How to assign AVPlayer play/pause button iOS?如何分配 AVPlayer 播放/暂停按钮 iOS?
【发布时间】:2013-02-19 15:09:53
【问题描述】:

我前几天问过这个问题,但没有人回答我,我找不到解决方案。

所以我想再次问同样的问题,如果你知道答案,请回答我。

我想将图片中的这些按钮分配给我的 avplayer 播放/暂停按钮。

注意:我的应用程序图标出现在正在播放的栏中,而不是音乐图标,我的应用程序在后台运行良好。

请帮忙。

【问题讨论】:

    标签: iphone ios ipad avplayer


    【解决方案1】:

    要允许传递远程控制事件,您必须调用UIApplication 的beginReceivingRemoteControlEvents 方法。

    然后您通过像这样实现remoteControlReceivedWithEvent: 方法来响应远程控制事件:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        ...
    
        [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
        [[UIApplication sharedApplication] becomeFirstResponder];
    
    
        return YES;
    }
    
    - (void)remoteControlReceivedWithEvent:(UIEvent *)event
    {
        switch (event.subtype)
        {
            case UIEventSubtypeRemoteControlPlay:
                // play code
                ...
                break;
            case UIEventSubtypeRemoteControlTogglePlayPause:
                // toggle code
                ...    
                break;
            case UIEventSubtypeRemoteControlNextTrack:
                // next code
                ...
                break;
            default:
                break;
        }
    }
    

    【讨论】:

      【解决方案2】:

      注意: “在 iOS 7.1 及更高版本中,使用共享的MPRemoteCommandCenter 对象注册远程控制事件。使用共享命令中心对象时不需要调用此方法(注意:beginReceivingRemoteControlEvents)。” (Source)

      【讨论】:

        猜你喜欢
        • 2011-11-12
        • 2016-10-25
        • 1970-01-01
        • 2021-09-02
        • 2019-06-25
        • 1970-01-01
        • 2014-12-05
        • 1970-01-01
        • 2023-03-19
        相关资源
        最近更新 更多