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
- 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.
- In your AppDelegate do the following:
- Swift
- Objective-C
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]?) -> Bool
return true
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
VPPlayer* vpPlayer = [[VPPlayer alloc] init];
[vpPlayer initializeCastWithAppId:@"your app Id"];
return YES;
}
- In your ViewController do the following:
- Swift
- Objective-C
// Your UIViewController
vpplayer.castParentViewController = UIViewController()
// Mini media controls conatiner
vpplayer._miniMediaControlsContainerView = UIView()
// Height constraint for Mini media controls container
vpplayer._miniMediaControlsHeightConstraint = NSLayoutConstraint()
vpplayer.castParentViewController = self;
vpplayer._miniMediaControlsContainerView = // mini media controls container (UIView)
vpplayer._miniMediaControlsHeightConstraint = // mini media controls height constraint (NSLayoutConstraint)
Queueing
- Swift
- Objective-C
// 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)
// To add a video in queue do the following:
[vpplayer addVideoToQueueWithVideo:video];
// To remove a video from queue do the following:
[vpplayer queueRemoveItemAt: NSInteger];
// To move a video from one position to another in queue do the following:
[vpplayer queueMoveItemFrom:NSInteger to:NSInteger];
// To play video from queue do the following:
[vpplayer playVideofromQueueWithIndex:NSinteger];
Callbacks
- Swift
- Objective-C
// 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
)
// To get callbacks from cast do the following:
vpplayer.castDelegate = self
// And implement these methods in your class
- (void)playingVideoChangedToSource:(NSString * _Nonnull)videoSource;
- (void)currentlyPlayingVideoWithEntity:(NSInteger)entityId;
- (void)sessionManagerWithSessionManager:(GCKSessionManager * _Nonnull)sessionManager willEnd:(GCKSession * _Nonnull)session playingEntityId:(NSInteger)playingEntityId lastKnownPosition:(NSTimeInterval)lastKnownPosition;
- (void)sessionManagerWithSessionManager:(GCKSessionManager * _Nonnull)sessionManager didStart:(GCKCastSession * _Nonnull)session;
- (void)sessionManagerWithSessionManager:(GCKSessionManager * _Nonnull)sessionManager didResumeCastSession:(GCKCastSession * _Nonnull)session;
- (void)sessionManagerWithSessionManager:(GCKSessionManager * _Nonnull)sessionManager didSuspend:(GCKCastSession * _Nonnull)session with:(GCKConnectionSuspendReason)reason;
- (void)sessionManagerWithSessionManager:(GCKSessionManager * _Nonnull)sessionManager didEnd:(GCKSession * _Nonnull)sessionn withError:(NSError * _Nullable)error;
- (void)sessionManagerWithSessionManager:(GCKSessionManager * _Nonnull)sessionManager didFfailToResumeSession:(GCKSession * _Nonnull)didFfailToResumeSession withError:(NSError * _Nullable)withError;
- (void)requestDidCompleteWithRequest:(GCKRequest * _Nonnull)request;
- (void)requestWithRequest:(GCKRequest * _Nonnull)request didFailWithError:(GCKError * _Nonnull)error;
- (void)requestWithRequest:(GCKRequest * _Nonnull)request didAbortWith:(GCKRequestAbortReason)abortReason;
- (void)miniMediaControlsViewControllerWithMiniMediaControlsViewController:(GCKUIMiniMediaControlsViewController * _Nonnull)miniMediaControlsViewController