summaryrefslogtreecommitdiff
path: root/extensions/TimedMediaHandler/resources/ext.tmh.OgvJsSupport.js
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/TimedMediaHandler/resources/ext.tmh.OgvJsSupport.js')
-rw-r--r--extensions/TimedMediaHandler/resources/ext.tmh.OgvJsSupport.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/extensions/TimedMediaHandler/resources/ext.tmh.OgvJsSupport.js b/extensions/TimedMediaHandler/resources/ext.tmh.OgvJsSupport.js
new file mode 100644
index 00000000..af3fd9f5
--- /dev/null
+++ b/extensions/TimedMediaHandler/resources/ext.tmh.OgvJsSupport.js
@@ -0,0 +1,67 @@
+( function( $, mw ) {
+
+ var support = mw.OgvJsSupport = {
+ /**
+ * Ensure that the OGVPlayer class is loaded before continuing.
+ *
+ * @return jQuery.Deferred
+ */
+ loadOgvJs: function() {
+ return $.Deferred( function( deferred ) {
+ if ( typeof OGVPlayer === 'undefined' ) {
+ mw.loader.using( 'ext.tmh.OgvJs', function() {
+ OGVLoader.base = support.basePath();
+ deferred.resolve();
+ } );
+ } else {
+ deferred.resolve();
+ }
+ });
+ },
+
+ /**
+ * Get the base path of ogv.js and friends.
+ *
+ * @return string
+ */
+ basePath: function() {
+ var ext = mw.config.get( 'wgExtensionAssetsPath' ),
+ binPlayers = ext + '/TimedMediaHandler/MwEmbedModules/EmbedPlayer/binPlayers';
+ return binPlayers + '/ogv.js';
+ },
+
+ /**
+ * Return a stub audio context
+ *
+ * This is used for iOS Safari to enable Web Audio by triggering an empty
+ * audio output channel during a user input event handler. Without that,
+ * audio is left disabled and won't work when we start things up after an
+ * asynchronous code load.
+ *
+ * @return AudioContext
+ */
+ initAudioContext: function() {
+ var AudioContext = window.AudioContext || window.webkitAudioContext;
+ if ( AudioContext ) {
+ var context = new AudioContext(),
+ node;
+ if ( context.createScriptProcessor ) {
+ node = context.createScriptProcessor( 1024, 0, 2 );
+ } else if ( context.createJavaScriptNode ) {
+ node = context.createJavaScriptNode( 1024, 0, 2 );
+ } else {
+ throw new Error( 'Bad version of web audio API?' );
+ }
+
+ // Don't actually run any audio, just start & stop the node
+ node.connect( context.destination );
+ node.disconnect();
+
+ return context;
+ } else {
+ return null;
+ }
+ }
+ };
+
+} )( jQuery, mediaWiki );