Set up the PTMediaPlayer
TVSDK provides tools for creating an advanced video player application (your Primetime player), which you can integrate with other Primetime components.
Use your platform's tools to create a player and connect it to the media player view in TVSDK, which has methods to play and manage videos. For example, TVSDK provides play and pause methods. You can create user interface buttons on your platform and set the buttons to call those TVSDK methods.
The PTMediaPlayer interface encapsulates the functionality and behavior of a media player object.
To set up your PTMediaPlayer :
- Fetch the media's URL from your user interface, for example, in a text field.
NSURL *url = [NSURL URLWithString:textFieldURL.text];
- Create PTMetadata .Assume that your method createMetada prepares metadata (see Advertising ).
PTMetadata *metadata = [self createMetadata]
- Create PTMediaPlayerItem by using your PTMetadata instance.
PTMediaPlayerItem *item = [[[PTMediaPlayerItem alloc] initWithUrl:url mediaId:yourMediaID metadata:metadata] autorelease];
- Add observers to notifications that TVSDK dispatches.
- Create PTMediaPlayer using your new PTMediaPlayerItem .
PTMediaPlayer *player = [PTMediaPlayer playerWithMediaPlayerItem:item];
- Set properties on your player.Here are some of the available PTMediaPlayer properties:
player.autoPlay = YES; player.closedCaptionDisplayEnabled = YES; player.videoGravity = PTMediaPlayerVideoGravityResizeAspect; player.allowsAirPlayVideo = YES;
- Set the player's view property.
CGRect playerRect = self.adPlayerView.frame; playerRect.origin = CGPointMake(0, 0); playerRect.size = CGSizeMake(self.adPlayerView.frame.size.width, self.adPlayerView.frame.size.height); [player.view setFrame:playerRect]; [player.view setAutoresizingMask: ( UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight )];
- Add the player's view in the current view's subview.
[self.adPlayerView setAutoresizesSubviews:YES]; [self.adPlayerView addSubview:(UIView *)player.view];
- Call play to start media playback.