阿里播放器文檔地址:https://help.aliyun.com/document_detail/62941.html?spm=a2c4g.11186623.2.24.6bed1c4ch1wxhu#h2-u9519u8BEFu4EE3u78014css
需加載文件:html
<link rel="stylesheet" href="https://g.alicdn.com/de/prismplayer/2.8.0/skins/default/aliplayer-min.css">瀏覽器
<script charset="utf-8" src="https://g.alicdn.com/de/prismplayer/2.8.0/aliplayer-h5-min.js"></script>cookie
阿里雲默認vid方式切換高清度失敗可自動切回,source方式不會自動切回ide
源碼:阿里雲
var player = new Aliplayer({ "id": "J_prismPlayer", "vid": VideoId, "playauth": PlayAuth, "qualitySort": "asc", "format": "m3u8", "mediaType": "video", "width": "100%", "height": playerheight, "autoplay": true, "isLive": false, "cover": CoverURL, "rePlay": false, "playsinline": true, "preload": true, "controlBarVisibility": "hover", "useH5Prism": true, "skinLayout": [{ "name": "bigPlayButton", "align": "blabs", "x": 30, "y": 80 }, { "name": "H5Loading", "align": "cc" }, { "name": "errorDisplay", "align": "tlabs", "x": 0, "y": 0 }, { "name": "infoDisplay" }, { "name": "tooltip", "align": "blabs", "x": 0, "y": 56 }, { "name": "thumbnail" }, { "name": "controlBar", "align": "blabs", "x": 0, "y": 0, "children": [{ "name": "progress", "align": "blabs", "x": 0, "y": 44 }, { "name": "playButton", "align": "tl", "x": 15, "y": 12 }, { "name": "timeDisplay", "align": "tl", "x": 10, "y": 7 }, { "name": "fullScreenButton", "align": "tr", "x": 10, "y": 12 }, { "name": "setting", "align": "tr", "x": 15, "y": 12 }, { "name": "volume", "align": "tr", "x": 5, "y": 10 } ] } ] }, function(player) { player._switchLevel = 0; console.log("播放器建立了。"); }); player.on('ready', function(e) { player.play(); }); //播放器快捷鍵 $(window).keydown(function(e) { e == e || Window.event; var Code = e.keyCode || e.which || e.charCode; if (Code == "32") { //空格鍵(暫停,播放) e.preventDefault(); var videoplay = $('input[name="videoplay"]').val(); //定義一個隱藏域 來區分播放狀態 if (videoplay == 0) { player.pause(); $('input[name="videoplay"]').val(1); } else { player.play(); $('input[name="videoplay"]').val(0); } } else if (Code == "37") { //左箭頭(後退) var videotimes = player.getDuration(); var playnum = player.getCurrentTime(); playnum = parseInt(playnum - 10); if (playnum <= (videotimes - 30)) { player.seek(playnum); } } else if (Code == "39") { //right(快進) var videotimes = player.getDuration(); var playnum = player.getCurrentTime(); playnum = parseInt(playnum + 10); if (playnum <= (videotimes + 30)) { player.seek(playnum); } } else if (Code == "38") { //up(音量+) e.preventDefault(); var nowvioce = player.getVolume(); if (nowvioce >= 1) { player.setVolume(1); } else { player.setVolume(nowvioce + 0.05); } } else if (Code == "40") { //down(音量-) e.preventDefault(); var nowvioce = player.getVolume(); if (nowvioce <= 0) { player.setVolume(0); } else { player.setVolume(nowvioce - 0.05); } } });
2.關於直播時切換清晰度的坑。spa
此時播放方式爲source,官網的值爲:'{「HD」:」address1」,」SD」:」address2」}’,即,每一個清晰度對應相應的地址,code
切換失敗,不會自動切回,須要判斷失敗,此時,須要找到原來正確的播放畫質,發現,存在cookie裏,selectedStreamLevel,orm
。。鄙人的代碼:cdn
player.on('error', function(e) { var getStatus = player.getStatus(); if (getStatus == 'error') { setCookie('selectedStreamLevel', 'LD', 365); } });
可能兩層判斷有點多餘哈,大體意思是,當播放失敗時,切回默認的'標清'畫質。此時,大部分瀏覽器會從新播放,but,,safari不行,,須要你手動點擊刷新按鈕,,safari這裏暫時不知道如何處理。
另外:判斷瀏覽器是否能夠自動播放代碼
player.on('autoplay', function(data) { if (data.paramData) //能夠自動播放 { console.log('能夠自動播放'); // console.log(data) //隱藏提示 } else //不能夠自動播放 { layer.msg('當前瀏覽器不可自動播放,請點擊左下角播放按鈕開始播放') //顯示提示用戶點擊播放 } });