123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017 |
- var AVProVideoWebGL =
- {
- /*isNumber: function (item) {
- return typeof(item) === "number" && !isNaN(item);
- },
- assert: function (equality, message) {
- if (!equality)
- console.log(message);
- },*/
- count: 0,
- players: [],
- isSafari: function() {
- return navigator.vendor && navigator.vendor.indexOf('Apple') > -1 && navigator.userAgent && navigator.userAgent.indexOf('CriOS') == -1 && navigator.userAgent.indexOf('FxiOS') == -1;
- },
- is_iOS: function() {
- return [
- 'iPad Simulator',
- 'iPhone Simulator',
- 'iPod Simulator',
- 'iPad',
- 'iPhone',
- 'iPod'
- ].includes(navigator.platform)
- // iPad on iOS 13 detection
- || (navigator.userAgent.includes("Mac") && "ontouchend" in document);
- },
- hasPlayer__deps: ["players"],
- hasPlayer: function (videoIndex)
- {
- if (videoIndex)
- {
- if (videoIndex == -1)
- {
- return false;
- }
- if (_players)
- {
- if (_players[videoIndex])
- {
- return true;
- }
- }
- }
- else
- {
- if (_players)
- {
- if (_players.length > 0)
- {
- return true;
- }
- }
- }
- return false;
- },
- AVPPlayerInsertVideoElement__deps: ["count", "players", "isSafari", "is_iOS"],
- AVPPlayerInsertVideoElement: function (path, idValues, externalLibrary)
- {
- if (!path) { return false; }
- // NOTE: When loading from the indexedDB (Application.persistentDataPath),
- // URL.createObjectURL() must be used get a valid URL. See:
- // http://www.misfitgeek.com/html5-off-line-storing-and-retrieving-videos-with-indexeddb/
- path = Pointer_stringify(path);
- _count++;
- var vid = document.createElement("video");
- var useNativeSrcPath = true;
- var hls = null;
- if (externalLibrary == 1)
- {
- useNativeSrcPath = false;
- var player = dashjs.MediaPlayer().create();
- player.initialize(vid, path, true);
- }
- else if (externalLibrary == 2 && !(_is_iOS() || _isSafari()))
- {
- useNativeSrcPath = false;
- hls = new Hls();
- hls.loadSource(path);
- hls.attachMedia(vid);
- hls.on(Hls.Events.MANIFEST_PARSED, function()
- {
- //video.play();
- });
- }
- else if (externalLibrary == 3)
- {
- //useNativeSrcPath = false;
- }
- // Some sources say that this is the proper way to catch errors...
- /*vid.addEventListener('error', function(event) {
- console.log("Error: " + event);
- }, true);*/
- var hasSetCanPlay = false;
- var playerIndex;
- var id = _count;
-
- var vidData = {
- id: id,
- video: vid,
- ready: false,
- hasMetadata: false,
- isStalled: false,
- buffering: false,
- lastErrorCode: 0,
- hlsjs: hls
- };
- _players.push(vidData);
- playerIndex = (_players.length > 0) ? _players.length - 1 : 0;
- /*const frameCounterCallback = function (timeNow, metadata) {
- console.log("got a frame! " + metadata.presentedFrames + " " + metadata.presentationTime);
- vid.requestVideoFrameCallback(frameCounterCallback);
- };
- if (HTMLVideoElement.prototype.requestVideoFrameCallback)
- {
- console.log("has frame callback support");
- vid.requestVideoFrameCallback(frameCounterCallback);
- }*/
- vid.oncanplay = function()
- {
- if (!hasSetCanPlay)
- {
- hasSetCanPlay = true;
- vidData.ready = true;
- }
- };
- vid.onloadedmetadata = function()
- {
- vidData.hasMetadata = true;
- };
- vid.oncanplaythrough = function()
- {
- vidData.buffering = false;
- };
- vid.onplaying = function()
- {
- vidData.buffering = false;
- vidData.isStalled = false;
- //console.log("PLAYING");
- };
- vid.onwaiting = function()
- {
- vidData.buffering = true;
- //console.log("WAITING");
- };
- vid.onstalled = function()
- {
- vidData.isStalled = true;
- //console.log("STALLED");
- }
- /*vid.onpause = function() {
- };*/
- vid.onended = function()
- {
- vidData.buffering = false;
- vidData.isStalled = false;
- //console.log("ENDED");
- };
- vid.ontimeupdate = function()
- {
- vidData.buffering = false;
- vidData.isStalled = false;
- //console.log("vid current time: ", this.currentTime);
- };
- vid.onerror = function(texture)
- {
- var err = "unknown error";
- switch (vid.error.code) {
- case 1:
- err = "video loading aborted";
- break;
- case 2:
- err = "network loading error";
- break;
- case 3:
- err = "video decoding failed / corrupted data or unsupported codec";
- break;
- case 4:
- err = "video not supported";
- break;
- }
- vidData.lastErrorCode = vid.error.code;
- console.log("Error: " + err + " (errorcode=" + vid.error.code + ")", "color:red;");
- };
- vid.crossOrigin = "anonymous";
- vid.preload = 'auto';
- vid.autoplay = false;
- if (_is_iOS())
- {
- vid.autoplay = true;
- vid.playsInline = true;
- }
- if (useNativeSrcPath)
- {
- vid.src = path;
- }
- HEAP32[(idValues>>2)] = playerIndex;
- HEAP32[(idValues>>2)+1] = id;
- return true;
- },
- AVPPlayerGetLastError__deps: ["players", "hasPlayer"],
- AVPPlayerGetLastError: function(playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return 0; }
- var ret = _players[playerIndex].lastErrorCode
- _players[playerIndex].lastErrorCode = 0;
- return ret;
- },
-
- AVPPlayerCreateVideoTexture__deps: ["players", "hasPlayer"],
- AVPPlayerCreateVideoTexture: function (textureId)
- {
- const texture = GLctx.createTexture();
- GL.textures[textureId] = texture;
- //console.log("creating textureId " +textureId + " : " + GL.textures[textureId]);
- GLctx.bindTexture(GLctx.TEXTURE_2D, texture);
- },
- AVPPlayerDestroyVideoTexture__deps: ["players", "hasPlayer"],
- AVPPlayerDestroyVideoTexture: function (textureId)
- {
- GLctx.deleteTexture(GL.textures[textureId]);
- },
- AVPPlayerFetchVideoTexture__deps: ["players", "hasPlayer"],
- AVPPlayerFetchVideoTexture: function (playerIndex, textureId, init)
- {
- if (!_hasPlayer(playerIndex)) { return; }
- //console.log("updating textureId " +textureId + " : " + GL.textures[textureId]);
- GLctx.bindTexture(GLctx.TEXTURE_2D, GL.textures[textureId]);
- //GLctx.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
- if (!init)
- {
- //GLctx.texImage2D(GLctx.TEXTURE_2D, 0, GLctx.RGBA, GLctx.RGBA, GLctx.UNSIGNED_BYTE, _players[playerIndex].video);
- GLctx.texSubImage2D(GLctx.TEXTURE_2D, 0, 0, 0, GLctx.RGBA, GLctx.UNSIGNED_BYTE, _players[playerIndex].video);
- }
- else
- {
- GLctx.texImage2D(GLctx.TEXTURE_2D, 0, GLctx.RGBA, GLctx.RGBA, GLctx.UNSIGNED_BYTE, _players[playerIndex].video);
- }
-
- //NB: This line causes the texture to not show unless something else is rendered (not sure why)
- //GLctx.bindTexture(GLctx.TEXTURE_2D, null);
- GLctx.texParameteri(GLctx.TEXTURE_2D, GLctx.TEXTURE_WRAP_S, GLctx.CLAMP_TO_EDGE);
- GLctx.texParameteri(GLctx.TEXTURE_2D, GLctx.TEXTURE_WRAP_T, GLctx.CLAMP_TO_EDGE);
- GLctx.pixelStorei(GLctx.UNPACK_FLIP_Y_WEBGL, false);
- },
- AVPPlayerUpdatePlayerIndex__deps: ["players", "hasPlayer"],
- AVPPlayerUpdatePlayerIndex: function (id)
- {
- var result = -1;
- if (!_hasPlayer()) { return result; }
- _players.forEach(function (currentVid, index)
- {
- if (currentVid != null && currentVid.id == id)
- {
- result = index;
- }
- });
- return result;
- },
- AVPPlayerWidth__deps: ["players", "hasPlayer"],
- AVPPlayerWidth: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return 0; }
- return _players[playerIndex].video.videoWidth;
- },
- AVPPlayerHeight__deps: ["players", "hasPlayer"],
- AVPPlayerHeight: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return 0; }
- return _players[playerIndex].video.videoHeight;
- },
- AVPPlayerReady__deps: ["players", "hasPlayer"],
- AVPPlayerReady: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- if (_players)
- {
- if (_players.length > 0)
- {
- if (_players[playerIndex])
- {
- return _players[playerIndex].ready;
- }
- }
- }
- else
- {
- return false;
- }
- //return _players[playerIndex].video.readyState >= _players[playerIndex].video.HAVE_CURRENT_DATA;
- },
- AVPPlayerClose__deps: ["players", "hasPlayer"],
- AVPPlayerClose: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return; }
- var vid = _players[playerIndex].video;
- // Setting 'src' to an empty string results in the onerror handler being invoked and producing log noise on Chrome.
- // Removing the src attribute and invoking load is a recommended best practice in the HTML Standard.
- // See https://html.spec.whatwg.org/multipage/media.html#best-practices-for-authors-using-media-elements
- vid.pause();
- vid.removeAttribute("src"); // Previous: vid.src = "";
- vid.load();
- if (_players[playerIndex].hlsjs != null)
- {
- _players[playerIndex].hlsjs.destroy();
- _players[playerIndex].hlsjs = null;
- }
- _players[playerIndex].video = null;
- _players[playerIndex] = null;
- var allEmpty = true;
- for (i = 0; i < _players.length; i++) {
- if (_players[i] != null) {
- allEmpty = false;
- break;
- }
- }
- if (allEmpty)
- {
- _players = [];
- }
- //_players = _players.splice(playerIndex, 1);
- // Remove from DOM
- //vid.parentNode.removeChild(vid);
- },
- AVPPlayerSetLooping__deps: ["players", "hasPlayer"],
- AVPPlayerSetLooping: function (playerIndex, loop)
- {
- if (!_hasPlayer(playerIndex)) { return; }
- _players[playerIndex].video.loop = loop;
- },
- AVPPlayerIsLooping__deps: ["players", "hasPlayer"],
- AVPPlayerIsLooping: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- return _players[playerIndex].video.loop;
- },
- AVPPlayerHasMetadata__deps: ["players", "hasPlayer"],
- AVPPlayerHasMetadata: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- return (_players[playerIndex].video.readyState >= 1);
- },
- AVPPlayerIsPlaying__deps: ["players", "hasPlayer"],
- AVPPlayerIsPlaying: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- var video = _players[playerIndex].video;
- return (!video.paused && !video.ended);// || video.seeking || video.readyState < video.HAVE_FUTURE_DATA);
- },
- AVPPlayerIsSeeking__deps: ["players", "hasPlayer"],
- AVPPlayerIsSeeking: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- return _players[playerIndex].video.seeking;
- },
- AVPPlayerIsPaused__deps: ["players", "hasPlayer"],
- AVPPlayerIsPaused: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- return _players[playerIndex].video.paused;
- },
- AVPPlayerIsFinished__deps: ["players", "hasPlayer"],
- AVPPlayerIsFinished: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- return _players[playerIndex].video.ended;
- },
- AVPPlayerIsBuffering__deps: ["players", "hasPlayer"],
- AVPPlayerIsBuffering: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- return _players[playerIndex].buffering;
- },
- AVPPlayerIsPlaybackStalled__deps: ["players", "hasPlayer"],
- AVPPlayerIsPlaybackStalled: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- return _players[playerIndex].isStalled;
- },
- AVPPlayerPlay__deps: ["players", "hasPlayer"],
- AVPPlayerPlay: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- // https://webkit.org/blog/7734/auto-play-policy-changes-for-macos/
- // https://developers.google.com/web/updates/2017/06/play-request-was-interrupted
- var playPromise = _players[playerIndex].video.play();
- if (playPromise !== undefined)
- {
- playPromise.then(function()
- {
- // Automatic playback started!
- // Show playing UI.
- })
- .catch(function(error)
- {
- // Auto-play was prevented
- // Show paused UI.
- return false;
- });
- }
- return true;
- },
- AVPPlayerPause__deps: ["players", "hasPlayer"],
- AVPPlayerPause: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return; }
- _players[playerIndex].video.pause();
- },
- AVPPlayerSeekToTime__deps: ["players", "hasPlayer"],
- AVPPlayerSeekToTime: function (playerIndex, timeSec, fast)
- {
- if (!_hasPlayer(playerIndex)) { return; }
- var vid = _players[playerIndex].video;
- if (vid.seekable && vid.seekable.length > 0)
- {
- var timeNorm = 0.0;
- if (vid.duration > 0.0)
- {
- timeNorm = timeSec / vid.duration;
- }
- for (i = 0; i < vid.seekable.length; i++)
- {
- if (timeNorm >= vid.seekable.start(i) && timeNorm <= vid.seekable.end(i))
- {
- if (fast && vid.fastSeek)
- {
- vid.fastSeek(timeNorm);
- }
- else
- {
- vid.currentTime = timeSec;
- }
- return;
- }
- }
- }
- else
- {
- if (timeSec == 0.0)
- {
- vid.load();
- }
- else
- {
- vid.currentTime = timeSec;
- }
- }
- },
- AVPPlayerGetCurrentTime__deps: ["players", "hasPlayer"],
- AVPPlayerGetCurrentTime: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return 0.0; }
- return _players[playerIndex].video.currentTime;
- },
- AVPPlayerGetDuration__deps: ["players", "hasPlayer"],
- AVPPlayerGetDuration: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return 0.0; }
- return _players[playerIndex].video.duration;
- },
- AVPPlayerGetPlaybackRate__deps: ["players", "hasPlayer"],
- AVPPlayerGetPlaybackRate: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return 0.0; }
- return _players[playerIndex].video.playbackRate;
- },
- AVPPlayerSetPlaybackRate__deps: ["players", "hasPlayer"],
- AVPPlayerSetPlaybackRate: function (playerIndex, rate)
- {
- if (!_hasPlayer(playerIndex)) { return; }
- _players[playerIndex].video.playbackRate = rate;
- },
- AVPPlayerSetMuted__deps: ["players", "hasPlayer"],
- AVPPlayerSetMuted: function (playerIndex, mute)
- {
- if (!_hasPlayer(playerIndex)) { return; }
- _players[playerIndex].video.muted = mute;
- },
- AVPPlayerIsMuted__deps: ["players", "hasPlayer"],
- AVPPlayerIsMuted: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- return _players[playerIndex].video.muted;
- },
- AVPPlayerSetVolume__deps: ["players", "hasPlayer"],
- AVPPlayerSetVolume: function (playerIndex, volume)
- {
- if (!_hasPlayer(playerIndex)) { return; }
- _players[playerIndex].video.volume = volume;
- },
- AVPPlayerGetVolume__deps: ["players", "hasPlayer"],
- AVPPlayerGetVolume: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return 0.0; }
- return _players[playerIndex].video.volume;
- },
- AVPPlayerHasVideo__deps: ["players", "hasPlayer"],
- AVPPlayerHasVideo: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- var isChrome = !!window.chrome && !!window.chrome.webstore;
- if (isChrome)
- {
- return Boolean(_players[playerIndex].video.webkitVideoDecodedByteCount > 0);
- }
-
- if (_players[playerIndex].video.videoTracks)
- {
- return Boolean(_players[playerIndex].video.videoTracks.length > 0);
- }
-
- return true;
- },
- AVPPlayerHasAudio__deps: ["players", "hasPlayer"],
- AVPPlayerHasAudio: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- return _players[playerIndex].video.mozHasAudio || Boolean(_players[playerIndex].video.webkitAudioDecodedByteCount) ||
- Boolean(_players[playerIndex].video.audioTracks && _players[playerIndex].video.audioTracks.length);
- },
- AVPPlayerGetDecodedFrameCount__deps: ["players", "hasPlayer"],
- AVPPlayerGetDecodedFrameCount: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return 0; }
- var vid = _players[playerIndex].video;
- if (vid.readyState <= HTMLMediaElement.HAVE_CURRENT_DATA) { return 0; }
- var frameCount = 0;
- if (vid.mozPresentedFrames)
- {
- frameCount = vid.mozPresentedFrames;
- }
- else if (vid.mozDecodedFrames)
- {
- frameCount = vid.mozDecodedFrames;
- }
- else if (vid.webkitDecodedFrameCount)
- {
- frameCount = vid.webkitDecodedFrameCount;
- }
- /*var q = vid.getVideoPlaybackQuality();
- if (q)
- {
- console.log("frames: " + q.totalVideoFrames + " " + q.droppedVideoFrames);
- }*/
- return frameCount;
- },
- AVPPlayerSupportedDecodedFrameCount__deps: ["players", "hasPlayer"],
- AVPPlayerSupportedDecodedFrameCount: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- var vid = _players[playerIndex].video;
- if (vid.mozPresentedFrames)
- {
- return true;
- }
- else if (vid.mozDecodedFrames)
- {
- return true;
- }
- else if (vid.webkitDecodedFrameCount)
- {
- return true;
- }
- return false;
- },
- AVPPlayerGetNumBufferedTimeRanges__deps: ["players", "hasPlayer"],
- AVPPlayerGetNumBufferedTimeRanges: function(playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return 0; }
- if (_players[playerIndex].video.buffered)
- {
- return _players[playerIndex].video.buffered.length;
- }
- return 0;
- },
- AVPPlayerGetTimeRangeStart__deps: ["players", "hasPlayer"],
- AVPPlayerGetTimeRangeStart: function(playerIndex, rangeIndex)
- {
- if (!_hasPlayer(playerIndex)) { return 0.0; }
- if (_players[playerIndex].video.buffered)
- {
- if(rangeIndex >= _players[playerIndex].video.buffered.length)
- {
- return 0.0;
- }
- return _players[playerIndex].video.buffered.start(rangeIndex);
- }
- return 0.0;
- },
- AVPPlayerGetTimeRangeEnd__deps: ["players", "hasPlayer"],
- AVPPlayerGetTimeRangeEnd: function(playerIndex, rangeIndex)
- {
- if (!_hasPlayer(playerIndex)) { return 0.0; }
- if (_players[playerIndex].video.buffered)
- {
- if(rangeIndex >= _players[playerIndex].video.buffered.length)
- {
- return 0.0;
- }
- return _players[playerIndex].video.buffered.end(rangeIndex);
- }
- return 0.0;
- },
- AVPPlayerGetVideoTrackCount__deps: ["players", "hasPlayer", "AVPPlayerHasVideo"],
- AVPPlayerGetVideoTrackCount: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return 0; }
- var result = 0;
- var tracks = _players[playerIndex].video.videoTracks;
- if (tracks)
- {
- result = tracks.length;
- }
- else
- {
- if (_AVPPlayerHasVideo(playerIndex))
- {
- result = 1;
- }
- }
- return result;
- },
- AVPPlayerGetAudioTrackCount__deps: ["players", "hasPlayer", "AVPPlayerHasAudio"],
- AVPPlayerGetAudioTrackCount: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return 0; }
- var result = 0;
- var tracks = _players[playerIndex].video.audioTracks;
- if (tracks)
- {
- result = tracks.length;
- }
- else
- {
- if (_AVPPlayerHasAudio(playerIndex))
- {
- result = 1;
- }
- }
- return result;
- },
- AVPPlayerGetTextTrackCount__deps: ["players", "hasPlayer"],
- AVPPlayerGetTextTrackCount: function (playerIndex)
- {
- if (!_hasPlayer(playerIndex)) { return 0; }
- var result = 0;
- var tracks = _players[playerIndex].video.textTracks;
- if (tracks)
- {
- result = tracks.length;
- }
- return result;
- },
- AVPPlayerSetActiveVideoTrack__deps: ["players", "hasPlayer"],
- AVPPlayerSetActiveVideoTrack: function (playerIndex, trackIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- var result = false;
- if (_players[playerIndex].video.videoTracks)
- {
- var tracks = _players[playerIndex].video.videoTracks;
- if (trackIndex >=0 && trackIndex < tracks.length)
- {
- tracks[trackIndex].selected = true;
- result = true;
- }
- }
- return result;
- },
- AVPPlayerSetActiveAudioTrack: ["players", "hasPlayer"],
- AVPPlayerSetActiveAudioTrack: function (playerIndex, trackIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- var result = false;
- if (_players[playerIndex].video.audioTracks)
- {
- var tracks = _players[playerIndex].video.audioTracks;
- if (trackIndex >=0 && trackIndex < tracks.length)
- {
- for (i = 0; i < tracks.length; i++)
- {
- tracks[i].enabled = (i === trackIndex);
- }
- result = true;
- }
- }
- return result;
- },
- AVPPlayerSetActiveTextTrack: ["players", "hasPlayer"],
- AVPPlayerSetActiveTextTrack: function (playerIndex, trackIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- var result = false;
- if (_players[playerIndex].video.textTracks)
- {
- var tracks = _players[playerIndex].video.textTracks;
- if (trackIndex >=0 && trackIndex < tracks.length)
- {
- for (i = 0; i < tracks.length; i++)
- {
- tracks[i].mode = (i === trackIndex)?"showing":"disabled";
- }
- result = true;
- }
- }
- return result;
- },
- AVPPlayerStringToBuffer: [],
- AVPPlayerStringToBuffer: function (text)
- {
- // Get size of the string
- var bufferSize = lengthBytesUTF8(text) + 1;
- // Allocate memory space
- var buffer = _malloc(bufferSize);
- // Copy old data to the new one then return it
- stringToUTF8(text, buffer, bufferSize);
- return buffer;
- },
- AVPPlayerGetVideoTrackName: ["players", "hasPlayer", "AVPPlayerStringToBuffer"],
- AVPPlayerGetVideoTrackName: function (playerIndex, trackIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- var result = null;
- var tracks = _players[playerIndex].video.videoTracks;
- if (tracks)
- {
- if (trackIndex >=0 && trackIndex < tracks.length)
- {
- result = _AVPPlayerStringToBuffer(tracks[trackIndex].label);
- }
- }
- return result;
- },
- AVPPlayerGetAudioTrackName: ["players", "hasPlayer", "AVPPlayerStringToBuffer"],
- AVPPlayerGetAudioTrackName: function (playerIndex, trackIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- var result = null;
- var tracks = _players[playerIndex].video.audioTracks;
- if (tracks)
- {
- if (trackIndex >=0 && trackIndex < tracks.length)
- {
- result = _AVPPlayerStringToBuffer(tracks[trackIndex].label);
- }
- }
- return result;
- },
- AVPPlayerGetTextTrackName: ["players", "hasPlayer", "AVPPlayerStringToBuffer"],
- AVPPlayerGetTextTrackName: function (playerIndex, trackIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- var result = null;
- var tracks = _players[playerIndex].video.textTracks;
- if (tracks)
- {
- if (trackIndex >=0 && trackIndex < tracks.length)
- {
- result = _AVPPlayerStringToBuffer(tracks[trackIndex].label);
- }
- }
- return result;
- },
- AVPPlayerGetVideoTrackLanguage: ["players", "hasPlayer", "AVPPlayerStringToBuffer"],
- AVPPlayerGetVideoTrackLanguage: function (playerIndex, trackIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- var result = null;
- var tracks = _players[playerIndex].video.videoTracks;
- if (tracks)
- {
- if (trackIndex >=0 && trackIndex < tracks.length)
- {
- result = _AVPPlayerStringToBuffer(tracks[trackIndex].language);
- }
- }
- return result;
- },
- AVPPlayerGetAudioTrackLanguage: ["players", "hasPlayer", "AVPPlayerStringToBuffer"],
- AVPPlayerGetAudioTrackLanguage: function (playerIndex, trackIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- var result = null;
- var tracks = _players[playerIndex].video.audioTracks;
- if (tracks)
- {
- if (trackIndex >=0 && trackIndex < tracks.length)
- {
- result = _AVPPlayerStringToBuffer(tracks[trackIndex].language);
- }
- }
- return result;
- },
- AVPPlayerGetTextTrackLanguage: ["players", "hasPlayer", "AVPPlayerStringToBuffer"],
- AVPPlayerGetTextTrackLanguage: function (playerIndex, trackIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- var result = null;
- var tracks = _players[playerIndex].video.textTracks;
- if (tracks)
- {
- if (trackIndex >=0 && trackIndex < tracks.length)
- {
- result = _AVPPlayerStringToBuffer(tracks[trackIndex].language);
- }
- }
- return result;
- },
- AVPPlayerIsVideoTrackActive: ["players", "hasPlayer", "AVPPlayerHasVideo"],
- AVPPlayerIsVideoTrackActive: function (playerIndex, trackIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- var result = false;
- var tracks = _players[playerIndex].video.videoTracks;
- if (tracks)
- {
- result = (tracks.selectedIndex === trackIndex);
- }
- else
- {
- result = _AVPPlayerHasVideo(playerIndex);
- }
- return result;
- },
- AVPPlayerIsAudioTrackActive: ["players", "hasPlayer", "AVPPlayerHasAudio"],
- AVPPlayerIsAudioTrackActive: function (playerIndex, trackIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- var result = false;
- var tracks = _players[playerIndex].video.audioTracks;
- if (tracks)
- {
- if (trackIndex >=0 && trackIndex < tracks.length)
- {
- result = tracks[trackIndex].enabled;
- }
- }
- else
- {
- result = _AVPPlayerHasAudio(playerIndex);
- }
- return result;
- },
- AVPPlayerIsTextTrackActive: ["players", "hasPlayer"],
- AVPPlayerIsTextTrackActive: function (playerIndex, trackIndex)
- {
- if (!_hasPlayer(playerIndex)) { return false; }
- var result = false;
- var tracks = _players[playerIndex].video.textTracks;
- if (tracks)
- {
- if (trackIndex >=0 && trackIndex < tracks.length)
- {
- result = (tracks[trackIndex].mode === "showing");
- }
- }
- return result;
- }
- };
- autoAddDeps(AVProVideoWebGL, 'count');
- autoAddDeps(AVProVideoWebGL, 'players');
- autoAddDeps(AVProVideoWebGL, 'hasPlayer');
- autoAddDeps(AVProVideoWebGL, 'AVPPlayerHasVideo');
- autoAddDeps(AVProVideoWebGL, 'AVPPlayerHasAudio');
- autoAddDeps(AVProVideoWebGL, 'AVPPlayerStringToBuffer');
- mergeInto(LibraryManager.library, AVProVideoWebGL);
|