NowPlayingConfig

@objcMembers
@objc(BMPNowPlayingConfig)
public class NowPlayingConfig : NSObject

Configures the current Now Playing information for the application. This information will be displayed wherever Now Playing information typically appears, such as the lock screen and inside the control center.

  • Enable the default behaviour of Now Playing information to be displayed on the lock-screen and inside the control center. Default is false.

    For a detailed list of the supported features in the default behaviour, check the Default Supported Features section.

    Note

    Enabling this flag will automatically treat ImaSettings.disableNowPlayingInfo as true.

    Note

    Enabling this flag will automatically treat TweaksConfig.updatesNowPlayingInfoCenter as false.

    Limitations

    • Currently the current Now Playing information is disabled during casting.

    Know issues

    • There is an unexpected behaviour when using the IMA SDK. The Google IMA SDK adds its own MPRemoteCommand for play/pause right when the ad starts loading (not when it started playing). Within this time window (approximately around 10 seconds) it’s possible that the Ad and the main content are playing at the same time when a user interacts with the Now Playing feature.

    Customization

    It is possible to customize or add additional information. Please ensure that your code is executed after the Player instance has been created.

    Adding a Command

    To add an additional command to the MPRemoteCommandCenter, simply add a new target to the command you want to show. In this example we add a likeCommand:

    // Get the shared MPRemoteCommandCenter
    let commandCenter = MPRemoteCommandCenter.shared()
    
    // Add handler for the new Command
    commandCenter.likeCommand.addTarget { event in
        // React to the like button interaction
        return .success
    }
    

    Removing a Command

    It is possible to remove one of the commands we add per default by removing all targets from a command.

    // Get the shared MPRemoteCommandCenter
    let commandCenter = MPRemoteCommandCenter.shared()
    
    // Remove all registered targets
    commandCenter.skipBackwardCommand.removeTarget(nil)
    

    The list of supported commands per default can be found at the Default Supported Features section.

    Customizing a Command

    Some commands, such as the skipBackwardsCommand, have additional customization options. For example it’s possible to change the skip interval to a custom value:

    // Get the shared MPRemoteCommandCenter
    let commandCenter = MPRemoteCommandCenter.shared()
    
    // Customize the Command
    commandCenter.skipBackwardCommand.preferredIntervals = [5]
    

    Overriding a Command

    In case you want to have a custom implementation for one of the commands we add per default, you can do so by first removing it and adding your own command.

    // Get the shared MPRemoteCommandCenter
    let commandCenter = MPRemoteCommandCenter.shared()
    
    // Remove all registered targets
    commandCenter.skipBackwardCommand.removeTarget(nil)
    
    // Add a new handler for the Command
    commandCenter.skipBackwardCommand.addTarget { [weak player] _ in
        guard let player else { return .commandFailed }
        // React to the skip backward button interaction
        return .success
    }
    

    Default Supported Features

    Here is the list of supported features in the default behavior.

    Populated Metadata

    • MPNowPlayingInfoPropertyAssetURL
    • MPMediaItemPropertyTitle
    • MPMediaItemPropertyArtwork
    • MPNowPlayingInfoPropertyIsLiveStream
    • MPNowPlayingInfoPropertyPlaybackRate
    • MPNowPlayingInfoPropertyDefaultPlaybackRate
    • MPNowPlayingInfoPropertyElapsedPlaybackTime
    • MPMediaItemPropertyPlaybackDuration

    Registered Commands

    • togglePlayPauseCommand
    • changePlaybackPositionCommand
    • skipForwardCommand
    • skipBackwardCommand

    The skip interval is specified by the MPSkipIntervalCommand.preferredIntervals and can be configured for the .skipForwardCommand and .skipBackwardCommand on the MPRemoteCommandCenter.shared() individually.

    Declaration

    Swift

    public var isNowPlayingInfoEnabled: Bool