forked from bytedance/xgplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix_pip' into 'xgplayer-2'
fix(xgplayer): 修复ios下pip和全屏冲突问题 See merge request toutiao-fe-arch/xgplayer!41
- Loading branch information
Showing
3 changed files
with
59 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,50 @@ | ||
|
||
import { PresentationMode, checkWebkitSetPresentationMode } from '../utils/util' | ||
|
||
let pip = function () { | ||
let player = this | ||
function onPipBtnClick () { | ||
if (player.video !== document.pictureInPictureElement) { | ||
player.video.requestPictureInPicture(); | ||
player.video.requestPictureInPicture() | ||
} else { | ||
document.exitPictureInPicture(); | ||
document.exitPictureInPicture() | ||
} | ||
} | ||
player.on('pipBtnClick', onPipBtnClick) | ||
|
||
player.video.addEventListener("enterpictureinpicture", function(pipWindow){ | ||
const onWebkitpresentationmodechanged = (e) => { | ||
const mode = player.video.webkitPresentationMode | ||
this.pMode = mode | ||
if (mode === PresentationMode.PIP) { | ||
// 进入pip模式 | ||
player.emit('requestPictureInPicture', e.pictureInPictureWindow) | ||
} else if (mode === PresentationMode.INLINE) { | ||
// 退出pip,进去inline模式 | ||
player.emit('exitPictureInPicture') | ||
} | ||
} | ||
|
||
player.video.addEventListener('enterpictureinpicture', function (pipWindow) { | ||
player.emit('requestPictureInPicture', pipWindow) | ||
}) | ||
|
||
player.video.addEventListener("leavepictureinpicture", function(){ | ||
player.video.addEventListener('leavepictureinpicture', function () { | ||
player.emit('exitPictureInPicture') | ||
}) | ||
|
||
checkWebkitSetPresentationMode(player.video) && | ||
player.video.addEventListener('webkitpresentationmodechanged', onWebkitpresentationmodechanged) | ||
|
||
function onDestroy () { | ||
player.off('pipBtnClick', onPipBtnClick) | ||
player.off('destroy', onDestroy) | ||
checkWebkitSetPresentationMode(player.video) && | ||
player.video.removeEventListener('webkitpresentationmodechanged', onWebkitpresentationmodechanged) | ||
} | ||
player.once('destroy', onDestroy) | ||
} | ||
|
||
export default { | ||
name: 'pip', | ||
method: pip | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters