Playing a video from plugin¶
Playing (or more correctly referring to) a video can be done in two ways.
Direct URL¶
The simple approach is just to add the direct URL to the movie in the item that the user selects:
page.appendItem('http://example.com/movie.mp4', 'video', {
title: 'The best movie ever made'
});
For cases when the movie is located on a static URL (like the example above) this might make sense.
However for most real world cases this is not enough. For those cases, you could instead go...
Via a video page¶
In this case the plugin adds a route to a URI that will be used to open the video.
var someid = 123;
page.appendItem('exampleapp:video:' + someid, 'video', {
title: 'The best movie ever made'
});
This will make Movian open exampleapp:video:123
when the user starts the video.
This page is then responsible for setting up video playback. In its simplest form it could work like this:
plugin.addURI('exampleapp:video:([0-9]*)', function(page, id) {
page.loading = false;
page.source = 'http://example.com/videos/' + id + '.mp4';
page.type = 'video';
});
The plugin is free to do whatever queries or computation it wants to in this function to be able to construct the video URL.
However, if the URL that's actually played by the video player (the URL in page.source) does not match the URI to the page the automatic playback of next video will not work as expected. To remedy this, you should use the videoparam meta URI and provide a canonicalUrl.
The videoparams meta URL¶
Just using a direct URL to play a video file have some deficiencies. Therefore Movian supports a type of meta URL that basically is a JSON object encoded to contain a lot of extra information about the video. To encode the videoparams from an object do like this:
page.source = "videoparams:" + showtime.JSONEncode({
...
});
Here's a list of fields that understood in the videoparams object. The only mandatory field is 'sources'.
Property | Type | Description |
---|---|---|
title | string | Title to display in OSD (If not set Movian will try to infer it from URL) |
no_fs_scan | bool | Disable attempt to scan for subtitles in video's folder. Most plugins streaming from internet probably want to set this |
no_subtitle_scan | bool | Turns off subtitle scanning (available from 4.9.346). Subtitles explicitly passed in subtitles (see below) are still included |
canonicalUrl | string | Static URI that represents the video. This is the URI that will be used for storing restart position, number of times the file have been played, etc And for that to work it must be equal to the page URI for the video. If you use page.redirect - make sure to assign canonicalUrl correspondingly to the first page you begin redirects from. See example below |
sources | list | List of video sources. See below for more info |
subtitles | list | List of subtitles. See below for more info |
icon | string | URL to the icon which will be shown in the bottom bar while video is playing |
backdrops | array | List of images for creating a slider show in the icon background of video item. Example: [{url: screenshot1},{url: screenshot2}...{url: screenshotN}] |
Additional properties used for subtitle lookup¶
Property | Type | Description |
---|---|---|
imdbid | string | IMDB ID of movie (if known). The 'tt' prefix should be included |
year | integer | Year of the movie |
season | integer | Season of TV show |
episode | integer | Episode of TV show |
Sources¶
Sources is a list of video URLs. The reason for it being a list is that multiple URLs are possible if there are multiple bitrates available. However, right now Movian will always pick the highest bitrate and never switch. (Note that the adaptive bitrate switching in HLS is something else and completely contained within the HLS player part of Movian)
Each source object is formatted like this:
Property | Type | Description |
---|---|---|
url | string | URL to video file |
bitrate | integer | Bitrate in bits per second |
mimetype | string | Mimetype of video. If set it will make video start a tad faster as Movian does not need to probe format |
Subtitles¶
If the plugin have access to subtitles those can be sent in the videoparams object as well.
Property | Type | Description |
---|---|---|
title | string | Name of subtitle |
url | string | URL to subtitle file |
language | string | Subtitle language in ISO 639-2 (Three letter language codes) |
source | string | Source of the subtitle (typically name of plugin or similar) |
Grand example¶
This example will (obviosly) just play Inception from example.com regardless of the video ID in the URL. But you should get the point.
plugin.addURI('exampleapp:video:([0-9]*)', function(page, id) {
page.loading = false;
page.source = "videoparams:" + showtime.JSONEncode({
title: 'Inception',
imdbid: 'tt1375666',
year: 2010,
no_fs_scan: true,
canonicalUrl: 'exampleapp:video:' + id,
sources: [{
url: "http://example.com/videos/Inception.avi",
bitrate: 10000000,
mimetype: "video/x-msvideo"
}],
subtitles: [{
url: "http://example.com/videos/Inception-eng.srt",
language: 'eng',
source: 'example plugin',
title: 'Best english subtitle'
}, {
url: "http://example.com/videos/Inception-swe.srt",
language: 'swe',
source: 'example plugin',
title: 'Best Swedish subtitle'
}]
});
page.type = 'video';
});