### Install ogv.js via npm Source: https://github.com/hajimehoshi/ogvjs/blob/master/README.md This command installs the ogv.js library using the Node Package Manager (npm). The distribution-ready files will be placed in the 'node_modules/ogv/dist' directory after successful installation. ```Shell npm install ogv ``` -------------------------------- ### Initialize OGVPlayer for Muted Playback on iOS Safari Source: https://github.com/hajimehoshi/ogvjs/blob/master/README.md This JavaScript snippet demonstrates how to initialize the OGVPlayer, mute it, set the media source, and begin playback. Muting the player before initiating script-triggered playback is a workaround specifically for iOS Safari's limitations, which otherwise prevents audio from starting outside of a user event handler and can cause the player to hang. ```JavaScript player = new OGVPlayer(); player.muted = true; player.src = 'path/to/file-with-audio.ogv'; player.play(); ``` -------------------------------- ### Instantiate and Use OGVPlayer Source: https://github.com/hajimehoshi/ogvjs/blob/master/README.md Demonstrates how to create an instance of `OGVPlayer` with or without options, append it to the DOM, set its source, and handle playback events, similar to `HTMLMediaElement`. ```JavaScript // Create a new player with the constructor var player = new OGVPlayer(); // Or with options var player = new OGVPlayer({ enableWebM: true }); // Now treat it just like a video or audio element containerElement.appendChild(player); player.src = 'path/to/media.ogv'; player.play(); player.addEventListener('ended', function() { // ta-da! }); ``` -------------------------------- ### Integrate ogv.js in Module Bundlers and Instantiate Player Source: https://github.com/hajimehoshi/ogvjs/blob/master/README.md This snippet illustrates how to import the ogv.js library into a Browserify or Webpack project using 'require()'. It also demonstrates setting the resource base path and instantiating a new 'OGVPlayer' instance for media playback, highlighting best practices for accessing public classes. ```JavaScript var ogv = require('ogv'); // Access public classes either as ogv.OGVPlayer or just OGVPlayer. // Your build/lint tools may be happier with ogv.OGVPlayer! ogv.OGVLoader.base = '/path/to/resources'; var player = new ogv.OGVPlayer(); ``` -------------------------------- ### Check OGVPlayer Compatibility with OGVCompat Source: https://github.com/hajimehoshi/ogvjs/blob/master/README.md Shows how to use `OGVCompat.supported()` to verify if the `OGVPlayer` is supported in the current environment before attempting to load the full player. This checks for various runtime requirements. ```JavaScript if (OGVCompat.supported('OGVPlayer')) { // go load the full player from ogv.js and instantiate stuff } ``` -------------------------------- ### Dynamically Load ogv.js with Version Parameter Source: https://github.com/hajimehoshi/ogvjs/blob/master/README.md Illustrates how to dynamically load the `ogv.js` script into the document's head, appending a cache-buster version parameter using the `OGVVersion` symbol for controlled loading. ```JavaScript var script = document.createElement('script'); script.src = 'ogv.js?version=' + encodeURIComponent(OGVVersion); document.querySelector('head').appendChild(script); ``` -------------------------------- ### Configure ogv.js Resource Base Path Source: https://github.com/hajimehoshi/ogvjs/blob/master/README.md This snippet demonstrates how to manually set the base path for ogv.js resources like 'ogv-demuxer-ogg.js', 'ogv-worker-audio.js', and 'dynamicaudio.swf'. This is necessary when the library is loaded via a bundler (e.g., browserify, webpack, or MediaWiki's ResourceLoader) that prevents auto-detection of resource paths. ```JavaScript OGVLoader.base = '/path/to/resources'; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.