简体   繁体   中英

How to assign AVPlayer play/pause button iOS?

I have asked this question before few days but nobody answer me and I could not find the solution.

So I want to ask the same question again and please answer me if you know the answer.

I want to assign these buttons in the picture to my avplayer play/pause button.

在此处输入图片说明

Note: My application icons appear in the now playing bar instead of Music icon, my application works fine in background .

Any help please.

To allow delivery of remote-control events, you must call the beginReceivingRemoteControlEvents method of UIApplication .

You then respond to the remote control events by implementing the remoteControlReceivedWithEvent: method like this:

- (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;
    }
}

Note: "In iOS 7.1 and later, use the shared MPRemoteCommandCenter object to register for remote control events. You do not need to call this method (note: beginReceivingRemoteControlEvents ) when using the shared command center object." ( Source )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM