Basic embedding

This section includes samples for basic player operations such as configuration. For additional examples, see the sample application

Configuration object

All the data needed to create a player should be populated in the configuration object before calling initializing a player. Here are some examples.

Additional player configuration params:

config.image    = @"/image.jpg";    //title image
config.title    = @"JWPlayer Demo"; // video title
config.controls = YES;              //show/hide controls
config.repeat   = NO;               //repeat after completion
config.image    = "/image.jpg"    //title image
config.title    = "JWPlayer Demo" // video title
config.controls = true            //show/hide controls
config.repeat   = false           //repeat after completion


Local file playback

The JW Player SDK for iOS supports playback of local files of the following formats: MP4 and M4V with H.264 & AAC/MP3.

To play a local file you need to specify the path to the file including file:// protocol.

NSString *pathNoScheme = [[NSBundle mainBundle] pathForResource:@"sintel" ofType:@"mp4"]];
NSString *path = [NSString stringWithFormat:@"file://%@", pathNoScheme];
// OR
NSString *path = [[NSURL URLwithString:pathNoScheme] absoluteString];
config.file = path;
var pathNoScheme = Bundle.main.path(forResource: "sintel", ofType: "mp4")!
var path = "file://\(pathNoScheme ?? "")"
// OR
var path = URL(string: pathNoScheme)?.absoluteString


Offline handling

You may specify a poster image to display when the device goes offline by setting a UIImage to the offlinePoster property of JWConfig, and you may specify a message to be displayed on top of the image by setting an NSString to the offlineMessage property of JWConfig.

config.offlinePoster  = [UIImage imageNamed:@"my_Image_Name.png"];
config.offlineMessage = @"my offline message";
config.offlinePoster  = UIImage(named: "my_Image_Name.png")
config.offlineMessage = "my offline message"

If the offlinePoster property is nil, the player will display the thumbnail image set to the image property of JWConfig. If both properties are nil, the player will display a black screen.
If the offlineMessage property is nil, the player will display its standard message "No Internet Connection".



Setting Multiple Sources

To create a player with multiple-source MP4 files, config.sources should be populated with an array of JWSource objects representing different MP4 objects, such as:

config.sources = @[
    [JWSource sourceWithFile:@"/example_low.mp4" label:@"180p Streaming" isDefault:YES],
    [JWSource sourceWithFile:@"/example_med.mp4" label:@"270p Streaming"],  
    [JWSource sourceWithFile:@"/example_hi.mp4"  label:@"720p Streaming"]
];
config.sources = [
    JWSource(file: "/example_low.mp4", label: "180p Streaming", isDefault: true),
    JWSource(file: "/example_med.mp4", label: "270p Streaming"),
    JWSource(file: "/example_hi.mp4" , label: "720p Streaming"),
]


Playlists

To create a playlist, an array of JWPlaylistItem objects called playlist is passed to the player.

JWPlaylistItem *item1 = [[JWPlaylistItem alloc] init];
item1.file            = @”http ://example.com/hls.m3u8”;
item1.tracks          = @[caption1, caption2];
item1.title           = @"Playlist Video With Captions";

JWPlaylistItem *item2 = [[JWPlaylistItem alloc] init];
item2.file            = @”http ://example.com/hls.m3u8”;
item2.adSchedule      = @[adBreak1, adBreak2];
item2.title           = @"Playlist Video With Ads";

config.playlist       = @[item1, item2];
var item1    = JWPlaylistItem()
item1.file   = "http ://example.com/hls.m3u8"
item1.tracks = [caption1, caption2]
item1.title  = "Playlist Video With Captions"

var item2        = JWPlaylistItem()
item2.file       = "http ://example.com/hls.m3u8"
item2.adSchedule = [adBreak1, adBreak2]
item2.title      = "Playlist Video With Ads"

config.playlist  = [item1, item2]

📘

NOTE

You can set an adSchedule for each JWPlaylistItem.

🚧

Video Selection UI Implementation

Take care to avoid creating a large number of player instances, as it may lead to app instability and memory-related crashes.

For example, consider the common case of displaying a playlist using a tableview, where the desired user experience is to tap a row to have it expand and play that row’s video. It is not recommended to have a player for each row, each loaded and ready to be selected.

Rather, you might architect your scene to use a single player controller, and have a lightweight placeholder in each row. On selection, the player would replace the placeholder the player’s view, load the desired video, and play.



Playback Rate

Our SDK allows you to set a playback speed, in a range between 0.25 to 4.

JWConfig *config            = [JWConfig new];
config.playbackRateControls = YES;

// Stop here for the default rates, or
// to specify custom rates, just set the property:
config.playbackRates = @[@0.5, @1, @2];

self.player = [[JWPlayerController alloc] initWithConfig:config];
var config = JWConfig()
config.playbackRateControls = true

// Stop here for the default rates, or
// to specify custom rates, just set the property:
config.playbackRates = [0.5, 1, 2]

player = JWPlayerController(config: config)

📘

NOTE

Certain streams' playback speed can only be decreased. Also, note that audio pitch is currently not adjusted.

Updated 2 months ago


Basic embedding


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.