Skip to content

Commit

Permalink
Fix bugs for iPhoneOS
Browse files Browse the repository at this point in the history
  • Loading branch information
HuongNV13 committed Sep 3, 2021
1 parent 61c9640 commit f9b12bd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "videojs-ogvjs",
"version": "0.1.0",
"version": "0.1.1",
"description": "Ogv.jv Tech plugin for Video.JS",
"main": "dist/videojs-ogvjs.cjs.js",
"module": "dist/videojs-ogvjs.es.js",
Expand Down
36 changes: 35 additions & 1 deletion src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import OGVLoader from 'OGVLoader';
import OGVPlayer from 'OGVPlayer';
const Tech = videojs.getComponent('Tech');

const androidOS = 'Android';
const iPhoneOS = 'iPhoneOS';
const iPadOS = 'iPadOS';
const otherOS = 'Other';

/**
* Object.defineProperty but "lazy", which means that the value is only set after
* it retrieved the first time, rather than being set right away.
Expand Down Expand Up @@ -37,6 +42,25 @@ const defineLazyProperty = function(obj, key, getValue, setter = true) {
return Object.defineProperty(obj, key, options);
};

/**
* Get the device's OS.
*
* @return {string} Device's OS.
*/
const getDeviceOS = function() {
/* global navigator */
const ua = navigator.userAgent;

if (/android/i.test(ua)) {
return androidOS;
} else if (/iPad|iPhone|iPod/.test(ua)) {
return iPhoneOS;
} else if ((navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)) {
return iPadOS;
}
return otherOS;
};

/**
* OgvJS Media Controller - Wrapper for ogv.js Media API
*
Expand All @@ -61,6 +85,13 @@ class OgvJS extends Tech {
OgvJS.setIfAvailable(this.el_, 'preload', options.preload);

this.on('loadedmetadata', function() {
if (getDeviceOS() === iPhoneOS) {
// iPhoneOS add some inline styles to the canvas, we need to remove it.
const canvas = this.el_.getElementsByTagName('canvas')[0];

canvas.style.removeProperty('width');
canvas.style.removeProperty('margin');
}
this.triggerReady();
});
}
Expand Down Expand Up @@ -213,7 +244,7 @@ class OgvJS extends Tech {
* @method setVolume
*/
setVolume(percentAsDecimal) {
if (this.el_.hasOwnProperty('volume')) {
if (getDeviceOS() !== iPhoneOS && this.el_.hasOwnProperty('volume')) {
this.el_.volume = percentAsDecimal;
}
}
Expand Down Expand Up @@ -596,6 +627,9 @@ OgvJS.canPlaySource = function(srcObj) {
* @return {boolean} True if volume can be controlled.
*/
OgvJS.canControlVolume = function() {
if (getDeviceOS() === iPhoneOS) {
return false;
}
const p = new OGVPlayer();

return p.hasOwnProperty('volume');
Expand Down

0 comments on commit f9b12bd

Please sign in to comment.