From 30b10f51a44b1ea1697b2e0cae0de2b156b32ba0 Mon Sep 17 00:00:00 2001 From: dorosh Date: Mon, 14 Nov 2016 16:31:39 +0200 Subject: [PATCH 1/2] add wistia video --- setup.py | 1 + video_xblock/static/html/wistiavideo.html | 11 +- video_xblock/static/html/youtube.html | 2 +- video_xblock/static/videojs-wistia/.gitignore | 8 + video_xblock/static/videojs-wistia/LICENSE | 22 + video_xblock/static/videojs-wistia/README.md | 71 +++ video_xblock/static/videojs-wistia/bower.json | 10 + .../static/videojs-wistia/example/index.html | 53 +++ .../static/videojs-wistia/package.json | 28 ++ .../static/videojs-wistia/src/wistia.js | 410 ++++++++++++++++++ .../static/videojs-wistia/vjs.wistia.js | 1 + video_xblock/video_xblock.py | 33 +- 12 files changed, 638 insertions(+), 12 deletions(-) create mode 100644 video_xblock/static/videojs-wistia/.gitignore create mode 100644 video_xblock/static/videojs-wistia/LICENSE create mode 100644 video_xblock/static/videojs-wistia/README.md create mode 100644 video_xblock/static/videojs-wistia/bower.json create mode 100644 video_xblock/static/videojs-wistia/example/index.html create mode 100644 video_xblock/static/videojs-wistia/package.json create mode 100644 video_xblock/static/videojs-wistia/src/wistia.js create mode 100644 video_xblock/static/videojs-wistia/vjs.wistia.js diff --git a/setup.py b/setup.py index 47e0dfb4..0306827c 100644 --- a/setup.py +++ b/setup.py @@ -38,6 +38,7 @@ def package_data(pkg, roots): ], 'video_xblock.v1': [ 'youtube-player = video_xblock:YoutubePlayer', + 'wistia-player = video_xblock:WistiaPlayer', 'brightcove-player = video_xblock:BrightcovePlayer', 'dummy-player = video_xblock:DummyPlayer', ] diff --git a/video_xblock/static/html/wistiavideo.html b/video_xblock/static/html/wistiavideo.html index 900dc964..c3d7f85b 100644 --- a/video_xblock/static/html/wistiavideo.html +++ b/video_xblock/static/html/wistiavideo.html @@ -1,9 +1,2 @@ -
- - -
-
-
 
-
-
-
+ \ No newline at end of file diff --git a/video_xblock/static/html/youtube.html b/video_xblock/static/html/youtube.html index d185fb05..fcd00935 100644 --- a/video_xblock/static/html/youtube.html +++ b/video_xblock/static/html/youtube.html @@ -6,6 +6,6 @@ autoplay {% endif %} width="640" height="264" - data-setup='{ "techOrder": ["youtube"], "sources": [{ "type": "video/youtube", "src": "{{ url }}"}], "youtube": { "iv_load_policy": 1 } }' + data-setup='{ "techOrder": ["youtube"], "sources": [{ "type": "video/youtube", "src": "{{ url }}"}], "youtube": { "iv_load_policy": 1 }, "playbackRates": [0.5, 1, 1.5, 2] }' > diff --git a/video_xblock/static/videojs-wistia/.gitignore b/video_xblock/static/videojs-wistia/.gitignore new file mode 100644 index 00000000..4cd4e390 --- /dev/null +++ b/video_xblock/static/videojs-wistia/.gitignore @@ -0,0 +1,8 @@ +# Windows image file caches +Thumbs.db + +# Folder config file +Desktop.ini + +# Mac crap +.DS_Store \ No newline at end of file diff --git a/video_xblock/static/videojs-wistia/LICENSE b/video_xblock/static/videojs-wistia/LICENSE new file mode 100644 index 00000000..55282bb5 --- /dev/null +++ b/video_xblock/static/videojs-wistia/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 ryanpatrickcook + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/video_xblock/static/videojs-wistia/README.md b/video_xblock/static/videojs-wistia/README.md new file mode 100644 index 00000000..0d182a9e --- /dev/null +++ b/video_xblock/static/videojs-wistia/README.md @@ -0,0 +1,71 @@ +# Video.js - Wistia Source Support +Allows you to use Wistia URL as source with [Video.js](https://github.com/videojs/video-js/). + +[Video.js 5 Example](http://ryanpatrickcook.github.io/videojs-wistia/) | +[Video.js 4 Example](http://ryanpatrickcook.github.io/videojs-wistia/index-vjs4.html) + +## How does it work? +Including the script vjs.wistia.js will add the Wistia as a tech. You just have to add it to your techOrder option. [Wistia Javascript Player API docs](http://wistia.com/doc/player-api). + +Here is an example of how to use with Javascript events: + + videojs('vid2', { + "techOrder": ["wistia"], + "sources": [{ + "type": "video/wistia", + "src": "http://fast.wistia.com/embed/iframe/b0767e8ebb?version=v1&controlsVisibleOnLoad=false&playerColor=aae3d8" + }] + }).ready(function() { + this.on('pause', function() { + document.body.style.backgroundColor = '#ffcccc'; + console.log("video.js - pause"); + }); + + this.on('play', function() { + document.body.style.backgroundColor = '#eafeea'; + console.log("video.js - play"); + }); + + this.on('seeked', function() { + console.log("video.js - seeked"); + }); + + this.on('volumechange', function() { + console.log("video.js - volumechange"); + }); + + this.one('ended', function() { + console.log("video.js - ended"); + this.src("https://home.wistia.com/medias/oefj398m6q?playerColor=ff0000"); + this.play(); + }); + }); + +If you're using video.js 4 (use the `video-js-4` branch) - Javascript events + + videojs('videoId', { + "techOrder": ["wistia"], + "src": "http://fast.wistia.com/embed/iframe/b0767e8ebb" + }).ready(function() { + this.on('pause', function() { + console.log("video.js - pause"); + }); + + this.on('play', function() { + console.log("video.js - play"); + }); + + this.on('seeked', function() { + console.log("video.js - seeked"); + }); + + this.on('volumechange', function() { + console.log("video.js - volumechange"); + }); + }); + + +## Supported URLs +http://fast.wistia.com/embed/iframe/:id + +http://home.wistia.com/medias/:id diff --git a/video_xblock/static/videojs-wistia/bower.json b/video_xblock/static/videojs-wistia/bower.json new file mode 100644 index 00000000..7791462f --- /dev/null +++ b/video_xblock/static/videojs-wistia/bower.json @@ -0,0 +1,10 @@ +{ + "name": "videojs-wistia", + "version": "2.0.0", + "main": ["vjs.wistia.js"], + "description": "Allows you to use Wistia URL as source with Video.js.", + "license": "MIT", + "dependencies": { + "video.js": "~5.10" + } +} diff --git a/video_xblock/static/videojs-wistia/example/index.html b/video_xblock/static/videojs-wistia/example/index.html new file mode 100644 index 00000000..0bf29e89 --- /dev/null +++ b/video_xblock/static/videojs-wistia/example/index.html @@ -0,0 +1,53 @@ + + + + + + + + +
+ + + + + + + + diff --git a/video_xblock/static/videojs-wistia/package.json b/video_xblock/static/videojs-wistia/package.json new file mode 100644 index 00000000..3d60c261 --- /dev/null +++ b/video_xblock/static/videojs-wistia/package.json @@ -0,0 +1,28 @@ +{ + "name": "videojs-wistia", + "version": "2.0.0", + "description": "Allows you to use Wistia URL as source with Video.js.", + "main": "vjs.wistia.js", + "repository": { + "type": "git", + "url": "git+https://github.com/ryanpatrickcook/videojs-wistia.git" + }, + "scripts": { + "dist": "mkdir -p dist && cp src/wistia.js dist/wistia.js && uglifyjs src/wistia.js -o dist/wistia.min.js", + "build": "uglifyjs src/wistia.js -o vjs.wistia.js" + }, + "devDependencies": { + "uglify-js": "^2.4.23" + }, + "keywords": [ + "video.js", + "wistia", + "plugin" + ], + "author": "Ryan Cook ", + "license": "MIT", + "bugs": { + "url": "https://github.com/ryanpatrickcook/videojs-wistia/issues" + }, + "homepage": "https://github.com/ryanpatrickcook/videojs-wistia#readme" +} diff --git a/video_xblock/static/videojs-wistia/src/wistia.js b/video_xblock/static/videojs-wistia/src/wistia.js new file mode 100644 index 00000000..66b005cf --- /dev/null +++ b/video_xblock/static/videojs-wistia/src/wistia.js @@ -0,0 +1,410 @@ +(function (root, factory) { + if(typeof define === 'function' && define.amd) { + define(['video.js'], function(videojs){ + return (root.WistiaTech = factory(videojs)); + }); + } else if(typeof module === 'object' && module.exports) { + module.exports = (root.WistiaTech = factory(require('video.js'))); + } else { + root.WistiaTech = factory(root.videojs); + } +}(this, function(videojs) { + 'use strict'; + + var WistiaState = { + UNSTARTED: -1, + ENDED: 0, + PLAYING: 1, + PAUSED: 2, + BUFFERING: 3 + }; + + var Tech = videojs.getComponent('Tech'); + + var WistiaTech = videojs.extend(Tech, { + constructor: function(options, ready) { + Tech.call(this, options, ready); + this.setSrc(this.options_.source.src, true); + }, + + dispose: function() { + this.wistiaVideo.remove(); + this.el_.parentNode.removeChild(this.el_); + }, + + createEl: function() { + var protocol = (document.location.protocol === 'file:') ? 'http:' : document.location.protocol; + this.wistia = {}; + this.wistiaInfo = {}; + this.baseUrl = protocol + '//fast.wistia.com/embed/iframe/'; + this.videoOptions = WistiaTech.parseUrl(this.options_.source.src); + this.videoId = this.videoOptions.videoId; + + var divWrapper = videojs.createEl('div', { + id: this.videoId, + className: this.videoOptions.classString, + width: this.options_.width || "100%", + height: this.options_ .height || "100%" + }); + + this.wistiaScriptElement = videojs.createEl('script', { + src: protocol + "//fast.wistia.com/assets/external/E-v1.js" + }); + + divWrapper.insertBefore(this.wistiaScriptElement, divWrapper.firstChild); + + this.initPlayer(); + + return divWrapper; + }, + + initPlayer: function() { + var self = this; + var wistiaVideoID = WistiaTech.parseUrl(this.options_.source.src).videoId; + + self.wistiaInfo = { + state: WistiaState.UNSTARTED, + volume: 1, + muted: false, + muteVolume: 1, + time: 0, + duration: 0, + buffered: 0, + url: self.baseUrl + self.videoId, + error: null + }; + + this.wistiaScriptElement.onload = function() { + self.wistiaVideo = Wistia.api(self.videoId); + window._wq = window._wq || []; + + var videos = {}; + videos[self.videoId] = function(video) { + self.wistiaVideo = video; + self.onLoad(); + }; + + window._wq.push(videos); + }; + }, + + onLoad: function() { + this.wistiaInfo = { + state: WistiaState.UNSTARTED, + volume: 1, + muted: false, + muteVolume: 1, + time: 0, + duration: 0, + buffered: 0, + url: this.baseUrl + this.videoId, + error: null + }; + + var self = this; + + this.wistiaVideo.hasData(function() { + self.onReady(); + }); + + this.wistiaVideo.bind('pause', function() { + self.onPause(); + }); + + this.wistiaVideo.bind('play', function() { + self.onPlay(); + }); + + this.wistiaVideo.bind('seek', function(currentTime, lastTime) { + self.onSeek({seconds: currentTime}); + }); + + this.wistiaVideo.bind('secondchange', function(s) { + self.wistiaInfo.time = s; + self.player_.trigger('timeupdate'); + + if( self.wistiaVideo.percentWatched() >= 1) { + self.onFinish(); + } + }); + + this.wistiaVideo.bind('volumechange', function(v) { + self.setVolume(v); + }); + + this.wistiaVideo.bind('end', function(t) { + self.onFinish(); + }); + }, + + onReady: function(){ + this.isReady_ = true; + this.triggerReady(); + this.trigger('loadedmetadata'); + if (this.startMuted) { + this.setMuted(true); + this.startMuted = false; + } + }, + + onLoadProgress: function(data) { + var durationUpdate = !this.wistiaInfo.duration; + this.wistiaInfo.duration = data.duration; + this.wistiaInfo.buffered = data.percent; + this.trigger('progress'); + if (durationUpdate) this.trigger('durationchange'); + }, + + onPlayProgress: function(data) { + this.wistiaInfo.time = data.seconds; + this.wistiaVideo.time(this.wistiaInfo.time); + this.trigger('timeupdate'); + }, + + onPlay: function() { + this.wistiaInfo.state = WistiaState.PLAYING; + this.trigger('play'); + }, + + onPause: function() { + this.wistiaInfo.state = WistiaState.PAUSED; + this.trigger('pause'); + }, + + onFinish: function() { + this.wistiaInfo.state = WistiaState.ENDED; + this.trigger('ended'); + }, + + onSeek: function(data) { + this.trigger('seeking'); + this.wistiaInfo.time = data.seconds; + this.wistiaVideo.time(this.wistiaInfo.time); + this.trigger('timeupdate'); + this.trigger('seeked'); + }, + + onError: function(error){ + this.error = error; + this.trigger('error'); + }, + + error: function() { + switch (this.errorNumber) { + case 2: + return { code: 'Unable to find the video' }; + + case 5: + return { code: 'Error while trying to play the video' }; + + case 100: + return { code: 'Unable to find the video' }; + + case 101: + case 150: + return { code: 'Playback on other Websites has been disabled by the video owner.' }; + } + + return { code: 'Wistia unknown error (' + this.errorNumber + ')' }; + }, + + src: function(src) { + if(src) { + this.setSrc({ src: src }); + } + return this.source; + }, + + setSrc: function(source) { + if(!source || !source.src) { + return; + } + + this.source = source; + this.videoOptions = WistiaTech.parseUrl(source.src); + this.wistiaVideo.replaceWith(this.videoOptions.videoId, this.videoOptions.options); + }, + + supportsFullScreen: function() { + return true; + }, + + load: function() {}, + + play: function() { + this.wistiaVideo.play(); + }, + + pause: function() { + this.wistiaVideo.pause(); + }, + + paused: function() { + return this.wistiaInfo.state !== WistiaState.PLAYING && + this.wistiaInfo.state !== WistiaState.BUFFERING; + }, + + currentTime: function() { + return this.wistiaInfo.time || 0; + }, + + setCurrentTime: function(seconds) { + this.wistiaVideo.time(seconds); + this.player_.trigger('timeupdate'); + }, + + duration: function() { + return this.wistiaInfo.duration || 0; + }, + + buffered: function() { + return videojs.createTimeRange(0, (this.wistiaInfo.buffered * this.wistiaInfo.duration) || 0); + }, + + volume: function() { + return (this.wistiaInfo.muted) ? this.wistiaInfo.muteVolume : this.wistiaInfo.volume; + }, + + setVolume: function(percentAsDecimal) { + this.wistiaInfo.volume = percentAsDecimal; + this.wistiaVideo.volume = percentAsDecimal; + this.player_.trigger('volumechange'); + }, + + currentSrc: function() { + return this.el_.src; + }, + + muted: function() { + return this.wistiaInfo.muted || false; + }, + + setMuted: function(muted) { + if(muted) { + this.wistiaInfo.muteVolume = this.wistiaInfo.volume; + this.setVolume(0); + } else { + this.setVolume(this.wistiaInfo.muteVolume); + } + + this.wistiaInfo.muted = muted; + this.player_.trigger('volumechange'); + } + }); + + WistiaTech.isSupported = function() { + return true; + }; + + WistiaTech.canPlaySource = function(e) { + return (e.type === 'video/wistia'); + }; + + WistiaTech.parseUrl = function(url) { + var result = { + videoId: null, + classes: [], + classString: '', + options: {} + }; + + var videoOptions = {}; + + var regex = regex = /^.*(wistia\.com\/)(embed\/iframe\/|medias\/)([A-z0-9]+)/; + var match = url.match(regex); + + if(match) { + result.videoId = match[3]; + } + + var classes = []; + classes.push('vjs-tech'); + classes.push('wistia_embed'); + classes.push('wistia_async_' + result.videoId); + + var options = {}; + options['wmode'] = 'transparent'; + + if(url) { + var playerColorMatch = url.match(/playerColor=([#a-fA-f0-9]+)/); + if(playerColorMatch) { + videoOptions.playerColor = playerColorMatch[1]; + } + + var controlsVisibleMatch = url.match(/controlsVisibleOnLoad=(true|false)/); + if(controlsVisibleMatch) { + videoOptions.controls = controlsVisibleMatch[1]; + } + + var autoPlayMatch = url.match(/autoplay=(true|false)/); + if(autoPlayMatch) { + videoOptions.autoplay = autoPlayMatch[1]; + } + + var mutedMatch = url.match(/muted=(true|false)/); + if(mutedMatch) { + videoOptions.muted = true; + } + + var volumeMatch = url.match(/volume=([0-9]+)/); + if(volumeMatch) { + videoOptions.volume = volumeMatch[1]; + } + + var endVideoBehaviorMatch = url.match(/endVideoBehavior=(loop|default|reset)/); + if(endVideoBehaviorMatch) { + videoOptions.endVideoBehavior = endVideoBehaviorMatch[1]; + } + } + + var color = videoOptions.playerColor; + if(color && color.substring(0, 1) === '#') { + videoOptions.playerColor = color.substring(1); + } + + if(videoOptions.controls) { + options['controlsVisibleOnLoad'] = videoOptions.controls; + } + + if(videoOptions.playerColor) { + options['playerColor'] = videoOptions.playerColor; + } + + if(videoOptions.autoplay) { + options['autoPlay'] = videoOptions.autoplay; + } + + if(videoOptions.volume !== false) { + options['volume'] = videoOptions.volume || 1; + } + + if(videoOptions.muted) { + options['volume'] = 0; + } + + if(videoOptions.loop) { + videoOptions.endVideoBehavior = 'loop'; + } + + if(videoOptions.endVideoBehavior) { + options['endVideoBehavior'] = videoOptions.endVideoBehavior; + } + + var keys = Object.keys(options); + var classString = classes.join(' ') + ' '; + for(var i = 0; i < keys.length; i++) { + var key = keys[i]; + var value = options[key]; + classString += key + '=' + value + '&'; + } + classString = classString.replace(/&+$/,''); + + result.classes = classes; + result.classString = classString; + result.options = options; + + return result; + }; + + videojs.registerTech('Wistia', WistiaTech); +})); diff --git a/video_xblock/static/videojs-wistia/vjs.wistia.js b/video_xblock/static/videojs-wistia/vjs.wistia.js new file mode 100644 index 00000000..dce50bd4 --- /dev/null +++ b/video_xblock/static/videojs-wistia/vjs.wistia.js @@ -0,0 +1 @@ +(function(root,factory){if(typeof define==="function"&&define.amd){define(["video.js"],function(videojs){return root.WistiaTech=factory(videojs)})}else if(typeof module==="object"&&module.exports){module.exports=root.WistiaTech=factory(require("video.js"))}else{root.WistiaTech=factory(root.videojs)}})(this,function(videojs){"use strict";var WistiaState={UNSTARTED:-1,ENDED:0,PLAYING:1,PAUSED:2,BUFFERING:3};var Tech=videojs.getComponent("Tech");var WistiaTech=videojs.extend(Tech,{constructor:function(options,ready){Tech.call(this,options,ready);this.setSrc(this.options_.source.src,true)},dispose:function(){this.wistiaVideo.remove();this.el_.parentNode.removeChild(this.el_)},createEl:function(){var protocol=document.location.protocol==="file:"?"http:":document.location.protocol;this.wistia={};this.wistiaInfo={};this.baseUrl=protocol+"//fast.wistia.com/embed/iframe/";this.videoOptions=WistiaTech.parseUrl(this.options_.source.src);this.videoId=this.videoOptions.videoId;var divWrapper=videojs.createEl("div",{id:this.videoId,className:this.videoOptions.classString,width:this.options_.width||"100%",height:this.options_.height||"100%"});this.wistiaScriptElement=videojs.createEl("script",{src:protocol+"//fast.wistia.com/assets/external/E-v1.js"});divWrapper.insertBefore(this.wistiaScriptElement,divWrapper.firstChild);this.initPlayer();return divWrapper},initPlayer:function(){var self=this;var wistiaVideoID=WistiaTech.parseUrl(this.options_.source.src).videoId;self.wistiaInfo={state:WistiaState.UNSTARTED,volume:1,muted:false,muteVolume:1,time:0,duration:0,buffered:0,url:self.baseUrl+self.videoId,error:null};this.wistiaScriptElement.onload=function(){self.wistiaVideo=Wistia.api(self.videoId);window._wq=window._wq||[];var videos={};videos[self.videoId]=function(video){self.wistiaVideo=video;self.onLoad()};window._wq.push(videos)}},onLoad:function(){this.wistiaInfo={state:WistiaState.UNSTARTED,volume:1,muted:false,muteVolume:1,time:0,duration:0,buffered:0,url:this.baseUrl+this.videoId,error:null};var self=this;this.wistiaVideo.hasData(function(){self.onReady()});this.wistiaVideo.bind("pause",function(){self.onPause()});this.wistiaVideo.bind("play",function(){self.onPlay()});this.wistiaVideo.bind("seek",function(currentTime,lastTime){self.onSeek({seconds:currentTime})});this.wistiaVideo.bind("secondchange",function(s){self.wistiaInfo.time=s;self.player_.trigger("timeupdate");if(self.wistiaVideo.percentWatched()>=1){self.onFinish()}});this.wistiaVideo.bind("volumechange",function(v){self.setVolume(v)});this.wistiaVideo.bind("end",function(t){self.onFinish()})},onReady:function(){this.isReady_=true;this.triggerReady();this.trigger("loadedmetadata");if(this.startMuted){this.setMuted(true);this.startMuted=false}},onLoadProgress:function(data){var durationUpdate=!this.wistiaInfo.duration;this.wistiaInfo.duration=data.duration;this.wistiaInfo.buffered=data.percent;this.trigger("progress");if(durationUpdate)this.trigger("durationchange")},onPlayProgress:function(data){this.wistiaInfo.time=data.seconds;this.wistiaVideo.time(this.wistiaInfo.time);this.trigger("timeupdate")},onPlay:function(){this.wistiaInfo.state=WistiaState.PLAYING;this.trigger("play")},onPause:function(){this.wistiaInfo.state=WistiaState.PAUSED;this.trigger("pause")},onFinish:function(){this.wistiaInfo.state=WistiaState.ENDED;this.trigger("ended")},onSeek:function(data){this.trigger("seeking");this.wistiaInfo.time=data.seconds;this.wistiaVideo.time(this.wistiaInfo.time);this.trigger("timeupdate");this.trigger("seeked")},onError:function(error){this.error=error;this.trigger("error")},error:function(){switch(this.errorNumber){case 2:return{code:"Unable to find the video"};case 5:return{code:"Error while trying to play the video"};case 100:return{code:"Unable to find the video"};case 101:case 150:return{code:"Playback on other Websites has been disabled by the video owner."}}return{code:"Wistia unknown error ("+this.errorNumber+")"}},src:function(src){if(src){this.setSrc({src:src})}return this.source},setSrc:function(source){if(!source||!source.src){return}this.source=source;this.videoOptions=WistiaTech.parseUrl(source.src);this.wistiaVideo.replaceWith(this.videoOptions.videoId,this.videoOptions.options)},supportsFullScreen:function(){return true},load:function(){},play:function(){this.wistiaVideo.play()},pause:function(){this.wistiaVideo.pause()},paused:function(){return this.wistiaInfo.state!==WistiaState.PLAYING&&this.wistiaInfo.state!==WistiaState.BUFFERING},currentTime:function(){return this.wistiaInfo.time||0},setCurrentTime:function(seconds){this.wistiaVideo.time(seconds);this.player_.trigger("timeupdate")},duration:function(){return this.wistiaInfo.duration||0},buffered:function(){return videojs.createTimeRange(0,this.wistiaInfo.buffered*this.wistiaInfo.duration||0)},volume:function(){return this.wistiaInfo.muted?this.wistiaInfo.muteVolume:this.wistiaInfo.volume},setVolume:function(percentAsDecimal){this.wistiaInfo.volume=percentAsDecimal;this.wistiaVideo.volume=percentAsDecimal;this.player_.trigger("volumechange")},currentSrc:function(){return this.el_.src},muted:function(){return this.wistiaInfo.muted||false},setMuted:function(muted){if(muted){this.wistiaInfo.muteVolume=this.wistiaInfo.volume;this.setVolume(0)}else{this.setVolume(this.wistiaInfo.muteVolume)}this.wistiaInfo.muted=muted;this.player_.trigger("volumechange")}});WistiaTech.isSupported=function(){return true};WistiaTech.canPlaySource=function(e){return e.type==="video/wistia"};WistiaTech.parseUrl=function(url){var result={videoId:null,classes:[],classString:"",options:{}};var videoOptions={};var regex=regex=/^.*(wistia\.com\/)(embed\/iframe\/|medias\/)([A-z0-9]+)/;var match=url.match(regex);if(match){result.videoId=match[3]}var classes=[];classes.push("vjs-tech");classes.push("wistia_embed");classes.push("wistia_async_"+result.videoId);var options={};options["wmode"]="transparent";if(url){var playerColorMatch=url.match(/playerColor=([#a-fA-f0-9]+)/);if(playerColorMatch){videoOptions.playerColor=playerColorMatch[1]}var controlsVisibleMatch=url.match(/controlsVisibleOnLoad=(true|false)/);if(controlsVisibleMatch){videoOptions.controls=controlsVisibleMatch[1]}var autoPlayMatch=url.match(/autoplay=(true|false)/);if(autoPlayMatch){videoOptions.autoplay=autoPlayMatch[1]}var mutedMatch=url.match(/muted=(true|false)/);if(mutedMatch){videoOptions.muted=true}var volumeMatch=url.match(/volume=([0-9]+)/);if(volumeMatch){videoOptions.volume=volumeMatch[1]}var endVideoBehaviorMatch=url.match(/endVideoBehavior=(loop|default|reset)/);if(endVideoBehaviorMatch){videoOptions.endVideoBehavior=endVideoBehaviorMatch[1]}}var color=videoOptions.playerColor;if(color&&color.substring(0,1)==="#"){videoOptions.playerColor=color.substring(1)}if(videoOptions.controls){options["controlsVisibleOnLoad"]=videoOptions.controls}if(videoOptions.playerColor){options["playerColor"]=videoOptions.playerColor}if(videoOptions.autoplay){options["autoPlay"]=videoOptions.autoplay}if(videoOptions.volume!==false){options["volume"]=videoOptions.volume||1}if(videoOptions.muted){options["volume"]=0}if(videoOptions.loop){videoOptions.endVideoBehavior="loop"}if(videoOptions.endVideoBehavior){options["endVideoBehavior"]=videoOptions.endVideoBehavior}var keys=Object.keys(options);var classString=classes.join(" ")+" ";for(var i=0;i.*)') + + def media_id(self, href): + return self.url_re.search(href).group('media_id') + + def get_frag(self, **context): + html = Template(self.resource_string("static/html/wistiavideo.html")) + frag = Fragment( + html_parser.unescape( + html.render(Context(context)) + ) + ) + frag.add_css(self.resource_string( + 'static/bower_components/video.js/dist/video-js.min.css' + )) + frag.add_javascript(self.resource_string( + 'static/bower_components/video.js/dist/video.min.js' + )) + frag.add_javascript(self.resource_string( + 'static/videojs-wistia/src/wistia.js' + )) + + return frag + + class VideoXBlock(StudioEditableXBlockMixin, XBlock): icon_class = "video" From ea493756f79c1f2e2a0ffe62ec5c04cf292a1847 Mon Sep 17 00:00:00 2001 From: dorosh Date: Mon, 14 Nov 2016 16:40:54 +0200 Subject: [PATCH 2/2] fix level code --- video_xblock/video_xblock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/video_xblock/video_xblock.py b/video_xblock/video_xblock.py index 2df9e039..9256ea17 100644 --- a/video_xblock/video_xblock.py +++ b/video_xblock/video_xblock.py @@ -156,7 +156,7 @@ def get_frag(self, **context): class WistiaPlayer(BaseVideoPlayer): - """ + """ WistiaPlayer is used for videos hosted on the Wistia Video Cloud """