Skip to content

Commit

Permalink
update support native play with safari which version large than 13
Browse files Browse the repository at this point in the history
  • Loading branch information
numberwolf committed Aug 24, 2022
1 parent 1c7ee55 commit 3761f44
Show file tree
Hide file tree
Showing 45 changed files with 65,233 additions and 211 deletions.
4 changes: 4 additions & 0 deletions README_EN.MD
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,10 @@ ffmpeg -ss 20 -t 10 -i ./res/xinxiaomen.mp4 \

| Update | Content |
| ---- | ---- |
| Time | 2022/08/24 |
| - | 0.Feature: Safari with native player(version>13) |
| Time | 2022/08/23 |
| - | 0.Fixed: Buffer Progress with AVC |
| Time | 2022/08/13 |
| - | 0.Support: Resize |
| Time | 2022/07/27 |
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist-multi-thread/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Github: https://github.com/numberwolf/h265web.js
*
**********************************************************/
require('./h265webjs-v20220813');
require('./h265webjs-v20220824');
export default class h265webjs {
static createPlayer(videoURL, config) {
return window.new265webjs(videoURL, config);
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Github: https://github.com/numberwolf/h265web.js
*
**********************************************************/
require('./h265webjs-v20220813');
require('./h265webjs-v20220824');
export default class h265webjs {
static createPlayer(videoURL, config) {
return window.new265webjs(videoURL, config);
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example_normal/dist-multi-thread/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Github: https://github.com/numberwolf/h265web.js
*
**********************************************************/
require('./h265webjs-v20220813');
require('./h265webjs-v20220824');
export default class h265webjs {
static createPlayer(videoURL, config) {
return window.new265webjs(videoURL, config);
Expand Down

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions example_normal/dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface ExtraConfig {
export interface Web265JsExtraConfig {
moovStartFlag?: boolean
rawFps?: number
autoCrop?: boolean
Expand Down Expand Up @@ -29,7 +29,7 @@ export interface Web265JsConfig {
* player token value
*/
token: string
extInfo?: ExtraConfig
extInfo?: Web265JsExtraConfig
}

export interface Web265JsMediaInfo {
Expand Down Expand Up @@ -76,15 +76,19 @@ interface New265WebJs {
playNextFrame(): void
snapshot(): void
release(): void
setPlaybackRate(rate: number): void
getPlaybackRate(): number
}

declare type new265webJsFn = (
url: string,
config: Web265JsConfig
) => New265WebJs

interface Window {
new265webjs: new265webJsFn
declare global {
interface Window {
new265webjs: new265webJsFn
}
}

export default class H265webjsModule {
Expand Down
2 changes: 1 addition & 1 deletion example_normal/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Github: https://github.com/numberwolf/h265web.js
*
**********************************************************/
require('./h265webjs-v20220813');
require('./h265webjs-v20220824');
export default class h265webjs {
static createPlayer(videoURL, config) {
return window.new265webjs(videoURL, config);
Expand Down
2 changes: 1 addition & 1 deletion example_normal/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<link rel="stylesheet" type="text/css" href='player-view/css/button.css'>
<link rel="stylesheet" type="text/css" href='player-view/css/progress.css'>
<script src="dist/missile.js"></script>
<script src="dist/h265webjs-v20220813.js"></script>
<script src="dist/h265webjs-v20220824.js"></script>
<script src="index.js"></script>

</head>
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example_vue/public/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Github: https://github.com/numberwolf/h265web.js
*
**********************************************************/
require('./h265webjs-v20220813');
require('./h265webjs-v20220824');
export default class h265webjs {
static createPlayer(videoURL, config) {
return window.new265webjs(videoURL, config);
Expand Down
4 changes: 2 additions & 2 deletions index-debug.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
<meta charset="utf-8" name="github" content="https://github.com/numberwolf/h265web.js">

<script src="dist/missile.js"></script> <!-- IMPORTANT -->
<script src="dist/h265webjs-v20220813.js"></script> <!-- IMPORTANT -->
<script src="dist/h265webjs-v20220824.js"></script> <!-- IMPORTANT -->

<!--<script src="dist-multi-thread/missile-multi-thread.js"></script>
<script src="dist-multi-thread/h265webjs-v20220813.js"></script>-->
<script src="dist-multi-thread/h265webjs-v20220824.js"></script>-->

<style>
</style>
Expand Down
24 changes: 24 additions & 0 deletions src/src/h265webjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1228,13 +1228,26 @@ class H265webjsModule {
const browser_info = AVCOMMON.BrowserJudge();
const browser_type = browser_info[0];
const browser_version = browser_info[1];
console.log("BrowserJudge:", browser_type, browser_version);
if (browser_type === 'Chrome' && browser_version < 85) {
return false;
}

if (browser_type.indexOf("360") >= 0) {
return false;
}

if(
(
/Safari/.test(navigator.userAgent)
&& !/Chrome/.test(navigator.userAgent)
) &&
browser_version > 13
) {
console.log("BrowserJudge:",
browser_version < 13, browser_version > 10);
return false;
}
}

return true;
Expand Down Expand Up @@ -1490,6 +1503,10 @@ class H265webjsModule {
this.player.onPlayState = (status) => {
_this.onPlayState && _this.onPlayState(status);
}; // onPlayState

this.player.onCacheProcess = (cPts) => {
_this.onCacheProcess && _this.onCacheProcess(cPts);
};
} // _makeNativePlayer

_initMp4BoxObject() {
Expand Down Expand Up @@ -2562,6 +2579,9 @@ class H265webjsModule {
this.player.onPlayState = (status) => {
_this.onPlayState && _this.onPlayState(status);
}; // onPlayState
this.player.onCacheProcess = (cPts) => {
_this.onCacheProcess && _this.onCacheProcess(cPts);
};
this.player.makeIt(this.videoURL);

} // _videoJsPlayer
Expand Down Expand Up @@ -2617,6 +2637,10 @@ class H265webjsModule {
_this.onPlayState && _this.onPlayState(status);
}; // onPlayState

this.player.onCacheProcess = (cPts) => {
_this.onCacheProcess && _this.onCacheProcess(cPts);
};

// this.player.onSeekFinish = () => {
// _this.onSeekFinish && _this.onSeekFinish();
// }; // onSeekFinish
Expand Down
2 changes: 1 addition & 1 deletion src/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Github: https://github.com/numberwolf/h265web.js
*
**********************************************************/
require('./h265webjs-v20220813');
require('./h265webjs-v20220824');
export default class h265webjs {
static createPlayer(videoURL, config) {
return window.new265webjs(videoURL, config);
Expand Down
24 changes: 24 additions & 0 deletions src/src/native/mp4-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ class Mp4PlayerModule {
this.duration = -1;
// this.fps = -1;

this.bufferInterval = null;

this.onLoadFinish = null;
this.onPlayingTime = null;
this.onPlayingFinish = null;
this.onPlayState = null;
this.onCacheProcess = null;

// this.onPlayUpdatePTSInterval = null;
}
Expand Down Expand Up @@ -93,6 +96,22 @@ class Mp4PlayerModule {
console.log("mp4-player loadedmetadata", e);
_this.duration = _this.videoTag.duration;
_this.onLoadFinish && _this.onLoadFinish();

if (_this.bufferInterval !== null) {
window.clearInterval(_this.bufferInterval);
_this.bufferInterval = null;
}

_this.bufferInterval = window.setInterval(function() {
const bufProgress = _this.videoTag.buffered.end(0);
console.log("bufProgress", bufProgress);
if (bufProgress >= _this.duration - 0.04) {
_this.onCacheProcess && _this.onCacheProcess(_this.duration);
window.clearInterval(_this.bufferInterval);
return;
}
_this.onCacheProcess && _this.onCacheProcess(bufProgress);
}, 200);
};

this.videoTag.src = url;
Expand Down Expand Up @@ -157,6 +176,11 @@ class Mp4PlayerModule {
this.onPlayingFinish = null;
this.onPlayState = null;

if (this.bufferInterval !== null) {
window.clearInterval(this.bufferInterval);
this.bufferInterval = null;
}

window.onclick = document.body.onclick = null;
}

Expand Down
33 changes: 33 additions & 0 deletions src/src/native/nv-flvjs-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class NvFlvjsCoreModule {
this.checkStartIntervalCount = 0;
this.checkStartInterval = null;
this.checkPicBlockInterval = null;

this.bufferInterval = null;
/*
* Event @todo
*/
Expand All @@ -76,6 +78,7 @@ class NvFlvjsCoreModule {
this.onPlayingFinish = null;
// this.onSeekFinish = null;
this.onReadyShowDone = null;
this.onCacheProcess = null;
} // constructor

_reBuildFlvjs(url) {
Expand Down Expand Up @@ -242,6 +245,7 @@ class NvFlvjsCoreModule {
alert("1 flvduration" + _this.duration);
_this.onLoadFinish && _this.onLoadFinish();
_this.onReadyShowDone && _this.onReadyShowDone();
_this._loopBufferState();
console.log("onReadyShowDone video isPlay", _this.isPlayingState());

_this.videoTag.ontimeupdate = () => {
Expand Down Expand Up @@ -277,6 +281,7 @@ class NvFlvjsCoreModule {
alert("1 flvduration" + _this.duration);
_this.onLoadFinish && _this.onLoadFinish();
_this.onReadyShowDone && _this.onReadyShowDone();
_this._loopBufferState();
console.log("onReadyShowDone video isPlay", _this.isPlayingState());

_this.videoTag.ontimeupdate = () => {
Expand Down Expand Up @@ -311,6 +316,7 @@ class NvFlvjsCoreModule {
alert("2 flvduration" + _this.duration);
_this.onLoadFinish && _this.onLoadFinish();
_this.onReadyShowDone && _this.onReadyShowDone();
_this._loopBufferState();
console.log("onReadyShowDone video isPlay", _this.isPlayingState());

_this.videoTag.ontimeupdate = () => {
Expand Down Expand Up @@ -410,6 +416,29 @@ class NvFlvjsCoreModule {
return !this.videoTag.paused;
}

_loopBufferState() {
let _this = this;
if (_this.duration <= 0) {
_this.duration = _this.videoTag.duration;
}

if (_this.bufferInterval !== null) {
window.clearInterval(_this.bufferInterval);
_this.bufferInterval = null;
}

_this.bufferInterval = window.setInterval(function() {
const bufProgress = _this.videoTag.buffered.end(0);
console.log("bufProgress", bufProgress);
if (bufProgress >= _this.duration - 0.04) {
_this.onCacheProcess && _this.onCacheProcess(_this.duration);
window.clearInterval(_this.bufferInterval);
return;
}
_this.onCacheProcess && _this.onCacheProcess(bufProgress);
}, 200);
}

_releaseFlvjs() {
this.myPlayer.pause();
this.myPlayer.unload();
Expand Down Expand Up @@ -444,6 +473,10 @@ class NvFlvjsCoreModule {
window.clearInterval(this.checkPicBlockInterval);
this.checkPicBlockInterval = null;
}
if (this.bufferInterval !== null) {
window.clearInterval(this.bufferInterval);
this.bufferInterval = null;
}
this._releaseFlvjs();

this.myPlayerID = null;
Expand Down
39 changes: 36 additions & 3 deletions src/src/native/nv-videojs-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ class NvVideojsCoreModule {
this.showScreen = false;

this.playPTS = 0;
this.vCachePTS = 0;
this.aCachePTS = 0;
// this.vCachePTS = 0;
// this.aCachePTS = 0;

this.bufferInterval = null;

/*
* Event @todo
* Event
*/
this.onMakeItReady = null;
this.onLoadFinish = null;
Expand All @@ -65,6 +67,7 @@ class NvVideojsCoreModule {
this.onSeekFinish = null;
this.onReadyShowDone = null;
this.onPlayState = null;
this.onCacheProcess = null;
} // constructor

_hiddenUnusedPlugins() {
Expand Down Expand Up @@ -195,6 +198,7 @@ class NvVideojsCoreModule {
if (_this.configFormat.probeDurationMS >= 0) {
_this.onLoadFinish && _this.onLoadFinish();
_this.onReadyShowDone && _this.onReadyShowDone();
_this._loopBufferState();
}
});
_this.myPlayer.on("ended", function() {
Expand All @@ -213,6 +217,7 @@ class NvVideojsCoreModule {
if (_this.configFormat.probeDurationMS < 0) {
_this.onLoadFinish && _this.onLoadFinish();
_this.onReadyShowDone && _this.onReadyShowDone();
_this._loopBufferState();
}
});
this.myPlayer.options.controls = false;
Expand Down Expand Up @@ -292,6 +297,29 @@ class NvVideojsCoreModule {
return !this.myPlayer.paused();
}

_loopBufferState() {
let _this = this;
if (_this.duration <= 0) {
_this.duration = _this.videoTag.duration;
}

if (_this.bufferInterval !== null) {
window.clearInterval(_this.bufferInterval);
_this.bufferInterval = null;
}

_this.bufferInterval = window.setInterval(function() {
const bufProgress = _this.videoTag.buffered.end(0);
console.log("bufProgress", bufProgress);
if (bufProgress >= _this.duration - 0.04) {
_this.onCacheProcess && _this.onCacheProcess(_this.duration);
window.clearInterval(_this.bufferInterval);
return;
}
_this.onCacheProcess && _this.onCacheProcess(bufProgress);
}, 200);
}

release() {
this.myPlayer.dispose();
this.myPlayerID = null
Expand All @@ -305,6 +333,11 @@ class NvVideojsCoreModule {
this.onReadyShowDone = null;
this.onPlayState = null;

if (this.bufferInterval !== null) {
window.clearInterval(this.bufferInterval);
this.bufferInterval = null;
}

window.onclick = document.body.onclick = null;
}

Expand Down
Loading

0 comments on commit 3761f44

Please sign in to comment.