Hello,
I would like to attach preroll advertisements against selected videos in my playlist. Going through the KONtx.mediaplayer, I cannot see an easy way of dynamically calling a video outside of my playlist, playing that, then resuming normal video playback.
Any ideas? Any documentation on this topic would help as well. Thank you.
This should get you started. It was taken and modified from the Fast Expiring Content Example in the mediaplayer docs.
CODE
var MyCustomPlaylistEntryClass = new KONtx.Class({
Extends: KONtx.media.PlaylistEntry,
config: {
url: null,
bitrate: null
},
initialize: function() {
this.parent();
this._urlsFetched = false;
},
streamsReady: function(callback) {
if(!this._urlsFetched) {
this._fetchContentURLs(callback);
return false;
} else {
return true;
}
},
_fetchContentURLs: function(callback) {
this.addURL(this.config.url, this.config.bitrate);
this._urlsFetched = true;
callback();
}
});
/*
so, you'd create your playlist like normal (taken from the Mediaplayer Sample widget in the wdk, full source available)
*/
_createPlaylist: function(playlistID) {
var playlist = new KONtx.media.Playlist();
playlist.PlaylistID = playlistID;
var json = KONtx.messages.fetch("playlist." + playlistID);
for each(var entry in json.entries) {
var playlistEntry = new KONtx.media.PlaylistEntry(entry);
playlistEntry.entryID = entry.entryID;
playlist.addEntry(playlistEntry);
}
//...snipped for brevity;
/*
and then you could add your custom playlist entries whenever according to what you need;
*/
playlist.addEntry(new MyCustomPlaylistEntryClass({
url: "http://www.example.com",
bitrate: 300
}));
playlist.addEntry(new MyCustomPlaylistEntryClass({
url: "http://www.example.com",
bitrate: 300
}));
/*
you can keep adding custom playlist entries or regular ones
*/
In my example, I hardcoded the url and bitrate, but you could make a fetch to a web service to get that data and then call this.addURL with the response. It's really up to you. Please see the mediaplayer docs under the aforementioned headline for more information.
Hope that helps.