ShadyGhalab / MediaRemoteControl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MediaRemoteControl

Swift 3.0.2

MediaRemoteControl is a framework that can handle any media using the external controls (play, pause, skipInterval, seekInterval,etc..) from the remote control and control center.

When to use:

You can use this framework when you want the user to use the external controls (remote control and control center) to manipulate the player (play,pause, etc..).

For instance: when the user is watching media in your app then the user locked the screen so he still can play the media through the external control. This is useful when the user want to play/pause his media from external controls that is shared with AirPlay without putting the app in the foreground.

Installation:

Carthage

github "ShadyGhalab/MediaRemoteControl" "1.2"

Cocoapods

pod 'MediaRemoteControl', '0.1.1'

How to use

         /* 
           1- Enable the background modes for "audio, airplay and picture in picture"
           2- Create your MediaItem.
           3- Initialize the RemoteControlManager with your mediaItem.
           4- Enjoy it 😎.
         */
         
        let mediaItem = MediaItem(withTitle: "Teacher", withDescription: "Play with his kids!",
                                  withSeasonEpisodeNumbers: (1,5),
                                  withDuration: (player?.currentItem?.asset.duration)!,
                                  artwork: UIImage(named:"Default"), artworkSize: CGSize(width: 200, height: 200),
                                  withBrand: "TV Land", skipInterval: 10)
        
        let remoteControlManager = RemoteControlManager(with: mediaItem)

        remoteControlManager?.didTapPlay = { [weak self] in
            self?.player?.play()
        }
        
        remoteControlManager?.didTapPause = { [weak self] in
            self?.player?.pause()
        }
        
        remoteControlManager?.didTapSkipForward = { [weak self] skipForwardInterval in
            self?.player?.seek(to: CMTimeAdd((self?.player?.currentTime())!, CMTimeMakeWithSeconds(skipForwardInterval, (self?.player?.currentTime().timescale)!)))
            return (self?.player?.currentTime())!
        }
        
        remoteControlManager?.didTapSkipBackward = { [weak self] skipBackwardInterval in
            self?.player?.seek(to: CMTimeSubtract((self?.player?.currentTime())!, CMTimeMakeWithSeconds(skipBackwardInterval, (self?.player?.currentTime().timescale)!)))
            return (self?.player?.currentTime())!
        }
        
        remoteControlManager?.didPlaybackPositionChange = { [weak self] positionTime in
            self?.player?.seek(to: CMTimeMakeWithSeconds(positionTime, 1000000))
        }   

Screenshots

alt tag alt tag

About


Languages

Language:Swift 95.1%Language:Ruby 3.5%Language:Objective-C 1.4%