Difference between revisions of "Video/Audio Plugin"
Line 307: | Line 307: | ||
== See also == | == See also == | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
* [[Plugin API Reference]] | * [[Plugin API Reference]] |
Latest revision as of 12:02, 12 June 2023
This is a small plugin guide to create your own video/audio plugin. It is designed for developers who have web programming skills (e.g. HTML, JavaScript, CSS, etc.). By the way, from the technical point of view, there are no differences between a video plugin and an audio plugin. You can load a video plugin as an audio plugin and vice versa. Therefore, there is only one API for both.
Note: For basic video/audio plugins, version 0.1.40 or higher is needed. For full-featured video/audio plugins, version 0.1.74 or higher is needed. Please note that it is recommended to only use the JavaScript ES5 (ECMAScript 2009) syntax for plugins, because most (especially older) TV browsers do not support the newer JavaScript ES6 (ECMAScript 2015) syntax. Please also note that newer JavaScript classes/libraries may not be supported by all TV browsers. Therefore, you should implement a good error handling to detect unsupported platforms.
Basics[edit]
A video/audio plugin is nothing more than a simple HTML page that is loaded into an iframe. You do not even need to add any JavaScript or CSS file. Therefore, any HTML page can be loaded as a video/audio plugin (at least if the page does not refuse it via the X-Frame-Options
HTTP header). Please see following example screenshot & code.
Screenshot[edit]
Note: The background color of the iframe is black.
Code[edit]
<!DOCTYPE html>
<html>
<head>
<title>My Video/Audio Plugin</title>
<style type="text/css">
h1 {
font-family: sans-serif;
color: white;
}
</style>
</head>
<body>
<h1>My Video/Audio Plugin</h1>
</body>
</html>
Interactions[edit]
A video/audio plugin will not receive any input (i.e. it is not possible to handle key, mouse, or touch events). Therefore, you should not implement any controls or buttons, because they can not be controlled anyway. The only task of a video/audio plugin is to show/play the video/audio output. All interactions (e.g. to set/get the current position, to set/get the playback speed, etc.) are managed by the TVXVideoPlugin
interface. Add the JavaScript file http://msx.benzac.de/js/tvx-plugin.min.js to your HTML page to make this interface available. Additionally, add some JavaScript lines to interact with this interface. Please see following example screenshot & code.
Screenshot[edit]
Code[edit]
<!DOCTYPE html>
<html>
<head>
<title>My Video/Audio Plugin</title>
<style type="text/css">
h1 {
font-family: sans-serif;
color: white;
}
</style>
<script type="text/javascript" src="//msx.benzac.de/js/tvx-plugin.min.js"></script>
<script type="text/javascript">
function MyPlayer() {
this.init = function() {
//Init player
};
this.ready = function() {
//Player is ready
TVXVideoPlugin.startPlayback();//This will call the play function and will start the update process
};
this.play = function() {
//Play
};
this.pause = function() {
//Pause
};
this.stop = function() {
//Stop
};
this.getDuration = function() {
//Get duration in seconds
return 60;
};
this.getPosition = function() {
//Get position in seconds
return 0;
};
this.setPosition = function(position) {
//Set position in seconds
if (position == 60) {
TVXVideoPlugin.stopPlayback();//Generally, this will unload the iframe
}
};
this.setVolume = function(volume) {
//Set volume (0 .. 100)
};
this.getVolume = function() {
//Get volume (0 .. 100)
return 100;
};
this.setMuted = function(muted) {
//Set muted
};
this.isMuted = function() {
//Get muted
return false;
};
this.getSpeed = function() {
//Get speed (0.125 .. 8.0)
return 1;
};
this.setSpeed = function(speed) {
//Set speed (0.125 .. 8.0)
};
this.getUpdateData = function() {
//Get update data (this will be called each second)
return {
position: this.getPosition(),
duration: this.getDuration(),
speed: this.getSpeed()
};
};
}
TVXPluginTools.onReady(function() {
TVXVideoPlugin.setupPlayer(new MyPlayer());
TVXVideoPlugin.init();
});
</script>
</head>
<body>
<h1>My Video/Audio Plugin</h1>
</body>
</html>
Note: It is recommended to reference the tvx-plugin.min.js
file without the protocol prefix (i.e. http:
or https:
) to support insecure and secure connections.
API[edit]
Beside the TVXVideoPlugin
interface, the JavaScript file exposes some more classes. Please see Plugin API Reference for more information.
Examples[edit]
Here are some examples that you can use as reference to implement your own video/audio plugin. Just open the implementation script or the link from the action syntax and analyze it with your browser developer tools (e.g. Chrome Developer Tools).
Screenshot[edit]
Code[edit]
{
"type": "list",
"headline": "Video Plugin Test",
"template": {
"type": "separate",
"layout": "0,0,2,4",
"icon": "msx-white-soft:extension",
"color": "msx-glass"
},
"items": [{
"title": "Template",
"playerLabel": "Template",
"action": "video:plugin:http://msx.benzac.de/plugins/template.html"
}, {
"badge": "{txt:msx-white:Html5}",
"badgeColor": "#000000",
"title": "Example Video",
"action": "video:plugin:http://msx.benzac.de/plugins/html5.html?url=http://msx.benzac.de/media/video3.mp4"
}, {
"badge": "{txt:msx-white:YouTube}",
"badgeColor": "#ff0000",
"title": "Example Video",
"playerLabel": "YouTube - Example Video",
"action": "video:plugin:http://msx.benzac.de/plugins/youtube.html?id=PRy2CFVlPOA"
}, {
"badge": "{txt:msx-white:Vimeo}",
"badgeColor": "#1ab7ea",
"title": "Example Video",
"playerLabel": "Vimeo - Example Video",
"action": "video:plugin:http://msx.benzac.de/plugins/vimeo.html?id=54802209"
}, {
"badge": "{txt:msx-white:Dailymotion}",
"badgeColor": "#00aaff",
"title": "Example Video",
"playerLabel": "Dailymotion - Example Video",
"action": "video:plugin:http://msx.benzac.de/plugins/dailymotion.html?id=xz14c1"
}, {
"badge": "{txt:msx-white:Twitch}",
"badgeColor": "#643fa6",
"title": "Example Video",
"playerLabel": "Twitch - Example Video",
"action": "video:plugin:http://msx.benzac.de/plugins/twitch.html?id=499763039"
}, {
"badge": "{txt:msx-white:Facebook}",
"badgeColor": "#4767aa",
"title": "Example Video",
"playerLabel": "Facebook - Example Video",
"action": "video:plugin:http://msx.benzac.de/plugins/facebook.html?id=10152454700553553"
}, {
"badge": "{txt:msx-white:Wistia}",
"badgeColor": "#5aaff2",
"title": "Example Video",
"playerLabel": "Wistia - Example Video",
"action": "video:plugin:http://msx.benzac.de/plugins/wistia.html?id=ve7pzy0d3y"
}, {
"badge": "{txt:msx-white:SoundCloud}",
"badgeColor": "#ff5500",
"title": "Example Track",
"playerLabel": "SoundCloud - Example Track",
"action": "video:plugin:http://msx.benzac.de/plugins/soundcloud.html?id=143041228"
}]
}
Demo[edit]
- Launch via App: https://msx.benzac.de/?start=content:https://msx.benzac.de/info/xp/data/plugin_test_1.json
- Launch via Demo Page: https://msx.benzac.de/info/?start=content:https://msx.benzac.de/info/xp/data/plugin_test_1.json