Skip to main content

Casting

Overview

The Google Cast framework enables a viewer to stream video and audio content to a compatible TV or sound system. By enabling the Google Cast framework in your app, a viewer can use a cast button to stream your content to a Chromecast-enabled device on a shared network connection.

Instructions

  1. Follow the instructions on https://developers.google.com/cast/docs/ios_sender and https://developers.google.com/cast/docs/ios_sender/ios_permissions_changes without doing any installation. VPPlayer has google cast already installed.
  2. In your AppDelegate do the following:
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]?) -> Bool
return true
}
  1. In your ViewController do the following:
// Your UIViewController
vpplayer.castParentViewController = UIViewController()
// Mini media controls conatiner
vpplayer._miniMediaControlsContainerView = UIView()
// Height constraint for Mini media controls container
vpplayer._miniMediaControlsHeightConstraint = NSLayoutConstraint()

Queueing

// To add a video in queue do the following:
vpplayer.addVideoToQueue (video: Video)
// To remove a video from queue do the following:
vpplayer.queueRemoveItem (at: Int)
// To move a video from one position to another in queue do the following:
vpplayer.queueMoveItem (from: Int, at: Int)
// To play video from queue do the following:
vpplayer.playVideoFromQueue (index: Int)
// To add a video to queue do the following:
vpplayer.addVideoToQueue(id: String)

Callbacks

// To get callbacks from cast do the following:
vpplayer.castDelegate = self // And implement these methods in your class
playingVideoChanged (toSource videoSource : String)
currentlyPlayingVideo(withVideoId videoId: Int)
sessionManager (
sessionManager : GCKSessionManager,
willEnd session : GCKSession,
playingEntityId : Int,
lastKnownPosition : TimeInterval
)
sessionManager (
sessionManager : GCKSessionManager,
didStart session : GCKCastSession
)
sessionManager (
sessionManager : GCKSessionManager,
didResumeCastSession session : GCKCastSession
)
sessionManager (
sessionManager : GCKSessionManager,
didSuspend session : GCKCastSession,
with reason : GCKConnectionSuspendReason
)
sessionManager (
sessionManager : GCKSessionManager,
didEnd sessionn : GCKSession,
withError error : Error?
)
sessionManager (
sessionManager : GCKSessionManager,
didFfailToResumeSession : GCKSession,
withError : Error?
)
requestDidComplete (request : GCKRequest)
request (request : GCKRequest,didFailWithError error : GCKError)
request (
request : GCKRequest,
didAbortWith abortReason : GCKRequestAbortReason
)
miniMediaControlsViewController (
miniMediaControlsViewController : GCKUIMiniMediaControlsViewController,
shouldAppear : Bool
)