Video/Audio Plugin

From MSX - Wiki
Jump to navigation Jump to search

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.

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]

Example Screenshot (My Video/Audio Plugin 1/2)

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]

Example Screenshot (My Video/Audio Plugin 2/2)

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="http://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()
                    };
                };
            }
            window.onload = function() {
                TVXVideoPlugin.setupPlayer(new MyPlayer());
                TVXVideoPlugin.init();
            };
        </script>
    </head>
    <body>
        <h1>My Video/Audio Plugin</h1>
    </body>
</html>

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).

Note: There is no guarantee that your video/audio plugin will work on each platform. Therefore, you should implement a good error handling to detect unsupported platforms.

Video/Audio plugin examples
Plugin Implementation Script & Related API Link Action Syntax
Template

http://msx.benzac.de/plugins/js/template.js

video:plugin:http://msx.benzac.de/plugins/template.html
audio:plugin:http://msx.benzac.de/plugins/template.html

HTML5

http://msx.benzac.de/plugins/js/html5.js
https://www.w3.org/TR/2011/WD-html5-20110113/video.html

video:plugin:http://msx.benzac.de/plugins/html5.html?url={URL}
audio:plugin:http://msx.benzac.de/plugins/html5.html?url={URL}

Dash

http://msx.benzac.de/plugins/js/dash.js
http://cdn.dashjs.org/latest/jsdoc/index.html

video:plugin:http://msx.benzac.de/plugins/dash.html?url={URL}
audio:plugin:http://msx.benzac.de/plugins/dash.html?url={URL}

Shaka

http://msx.benzac.de/plugins/js/shaka.js
https://shaka-player-demo.appspot.com/docs/api/index.html

video:plugin:http://msx.benzac.de/plugins/shaka.html?url={URL}
audio:plugin:http://msx.benzac.de/plugins/shaka.html?url={URL}

Has

http://msx.benzac.de/plugins/js/has.js
http://orange-opensource.github.io/hasplayer.js/latest/doc/jsdoc/index.html

video:plugin:http://msx.benzac.de/plugins/has.html?url={URL}
audio:plugin:http://msx.benzac.de/plugins/has.html?url={URL}

YouTube

http://msx.benzac.de/plugins/js/youtube.js
https://developers.google.com/youtube/iframe_api_reference

video:plugin:http://msx.benzac.de/plugins/youtube.html?id={ID}
audio:plugin:http://msx.benzac.de/plugins/youtube.html?id={ID}

Vimeo

http://msx.benzac.de/plugins/js/vimeo.js
https://github.com/vimeo/player.js

video:plugin:http://msx.benzac.de/plugins/vimeo.html?id={ID}
audio:plugin:http://msx.benzac.de/plugins/vimeo.html?id={ID}

Dailymotion

http://msx.benzac.de/plugins/js/dailymotion.js
https://developer.dailymotion.com/player

video:plugin:http://msx.benzac.de/plugins/dailymotion.html?id={ID}
audio:plugin:http://msx.benzac.de/plugins/dailymotion.html?id={ID}

Twitch

http://msx.benzac.de/plugins/js/twitch.js
https://dev.twitch.tv/docs/embed/video-and-clips

video:plugin:http://msx.benzac.de/plugins/twitch.html?id={ID}
audio:plugin:http://msx.benzac.de/plugins/twitch.html?id={ID}

Facebook

http://msx.benzac.de/plugins/js/facebook.js
https://developers.facebook.com/docs/plugins/embedded-video-player/api/

video:plugin:http://msx.benzac.de/plugins/facebook.html?id={ID}
audio:plugin:http://msx.benzac.de/plugins/facebook.html?id={ID}

Wistia

http://msx.benzac.de/plugins/js/wistia.js
https://wistia.com/support/developers/player-api

video:plugin:http://msx.benzac.de/plugins/wistia.html?id={ID}
audio:plugin:http://msx.benzac.de/plugins/wistia.html?id={ID}

SoundCloud

http://msx.benzac.de/plugins/js/soundcloud.js
https://developers.soundcloud.com/docs/api/html5-widget

video:plugin:http://msx.benzac.de/plugins/soundcloud.html?id={ID}
audio:plugin:http://msx.benzac.de/plugins/soundcloud.html?id={ID}

Screenshot[edit]

Example Screenshot (Video Plugin Test)

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=DQuhA5ZCV9M"
        }, {
            "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]

See also[edit]