This commit is contained in:
Harvey Zack committed 2019-08-06 13:26:39 +08:00
1 parent 8d8258eb42
commit fba16c2432
2 files changed
+4 -2

No files matched your search

+3 -1
View File
@@ -78,7 +78,9 @@
});
art.on('video:ended', function () {
nextVideo().then(function () {
sleep(1000).then(player.play);
sleep(1000).then(function () {
player.play = true;
});
});
});
art.on('afterAttachUrl', function () {
@@ -1 +1 @@
{"version":3,"file":"artplayer-plugin-playlist.js","sources":["../../packages/artplayer-plugin-playlist/src/index.js"],"sourcesContent":["import './index.scss';\n\nfunction artplayerPluginPlaylist(list) {\n return art => {\n const {\n utils: { append, errorHandle, sleep, inverseClass },\n } = art.constructor;\n const {\n player,\n events: { proxy },\n template: { $player, $video },\n } = art;\n\n const $playlist = append(\n $player,\n `\n <div class=\"artplayer-playlist\">\n <div class=\"artplayer-playlist-inner\"></div>\n </div>\n `,\n );\n\n errorHandle(Array.isArray(list), 'Playlist is not an array type');\n errorHandle(list.length > 0, 'Playlist cannot be empty');\n const playlist = list.map(item => {\n errorHandle(item.url, 'Playlist items require url attribute');\n errorHandle(item.title, 'Playlist items require title attribute');\n return item;\n });\n\n const $playlistInner = $playlist.querySelector('.artplayer-playlist-inner');\n $playlistInner.innerHTML = playlist\n .map((item, index) => {\n return `<div class=\"artplayer-playlist-item\" data-option-index=\"${index}\">${item.title}</div>`;\n })\n .join('');\n\n function switchUrl(index) {\n const itemOption = playlist[index];\n return player.switchUrl(itemOption.url, itemOption.title).then(() => {\n art.emit('artplayerPluginPlaylist:change', itemOption);\n });\n }\n\n function prevVideo() {\n const index = playlist.findIndex(item => item.url === $video.src);\n errorHandle(index !== -1, \"Can't find Playlist item\");\n if (playlist.length === 1) {\n return switchUrl(0);\n }\n const prevIndex = index - 1 === -1 ? playlist.length - 1 : index - 1;\n return switchUrl(prevIndex);\n }\n\n function nextVideo() {\n const index = playlist.findIndex(item => item.url === $video.src);\n errorHandle(index !== -1, \"Can't find Playlist item\");\n if (playlist.length === 1) {\n return switchUrl(0);\n }\n const nextIndex = index + 1 === playlist.length ? 0 : index + 1;\n return switchUrl(nextIndex);\n }\n\n proxy($playlistInner, 'click', e => {\n const { optionIndex } = e.target.dataset;\n if (optionIndex && Number(optionIndex) <= playlist.length - 1) {\n switchUrl(optionIndex);\n }\n });\n\n proxy($playlist, 'click', e => {\n if (e.target === $playlist) {\n $player.classList.remove('artplayer-playlist-show');\n }\n });\n\n art.on('video:ended', () => {\n nextVideo().then(() => {\n sleep(1000).then(player.play);\n });\n });\n\n art.on('afterAttachUrl', () => {\n const index = playlist.findIndex(item => item.url === $video.src);\n const $item = Array.from($playlistInner.children)[index];\n if (index !== -1 && $item) {\n inverseClass($item, 'active');\n }\n });\n\n return {\n name: 'artplayerPluginPlaylist',\n show() {\n $player.classList.add('artplayer-playlist-show');\n },\n hide() {\n $player.classList.remove('artplayer-playlist-show');\n },\n next() {\n nextVideo();\n },\n prev() {\n prevVideo();\n },\n };\n };\n}\n\nexport default artplayerPluginPlaylist;\n"],"names":["artplayerPluginPlaylist","list","art","constructor","utils","append","errorHandle","sleep","inverseClass","player","proxy","events","template","$player","$video","$playlist","Array","isArray","length","playlist","map","item","url","title","$playlistInner","querySelector","innerHTML","index","join","switchUrl","itemOption","then","emit","prevVideo","findIndex","src","prevIndex","nextVideo","nextIndex","e","optionIndex","target","dataset","Number","classList","remove","on","play","$item","from","children","name","show","add","hide","next","prev"],"mappings":";;;;;;IAEA,SAASA,uBAAT,CAAiCC,IAAjC,EAAuC;IACnC,SAAO,UAAAC,GAAG,EAAI;IAAA,gCAGNA,GAAG,CAACC,WAHE,CAENC,KAFM;IAAA,QAEGC,MAFH,yBAEGA,MAFH;IAAA,QAEWC,WAFX,yBAEWA,WAFX;IAAA,QAEwBC,KAFxB,yBAEwBA,KAFxB;IAAA,QAE+BC,YAF/B,yBAE+BA,YAF/B;IAAA,QAKNC,MALM,GAQNP,GARM,CAKNO,MALM;IAAA,QAMIC,KANJ,GAQNR,GARM,CAMNS,MANM,CAMID,KANJ;IAAA,wBAQNR,GARM,CAONU,QAPM;IAAA,QAOMC,OAPN,iBAOMA,OAPN;IAAA,QAOeC,MAPf,iBAOeA,MAPf;IAUV,QAAMC,SAAS,GAAGV,MAAM,CACpBQ,OADoB,mJAAxB;IASAP,IAAAA,WAAW,CAACU,KAAK,CAACC,OAAN,CAAchB,IAAd,CAAD,EAAsB,+BAAtB,CAAX;IACALine truncated
{"version":3,"file":"artplayer-plugin-playlist.js","sources":["../../packages/artplayer-plugin-playlist/src/index.js"],"sourcesContent":["import './index.scss';\n\nfunction artplayerPluginPlaylist(list) {\n return art => {\n const {\n utils: { append, errorHandle, sleep, inverseClass },\n } = art.constructor;\n const {\n player,\n events: { proxy },\n template: { $player, $video },\n } = art;\n\n const $playlist = append(\n $player,\n `\n <div class=\"artplayer-playlist\">\n <div class=\"artplayer-playlist-inner\"></div>\n </div>\n `,\n );\n\n errorHandle(Array.isArray(list), 'Playlist is not an array type');\n errorHandle(list.length > 0, 'Playlist cannot be empty');\n const playlist = list.map(item => {\n errorHandle(item.url, 'Playlist items require url attribute');\n errorHandle(item.title, 'Playlist items require title attribute');\n return item;\n });\n\n const $playlistInner = $playlist.querySelector('.artplayer-playlist-inner');\n $playlistInner.innerHTML = playlist\n .map((item, index) => {\n return `<div class=\"artplayer-playlist-item\" data-option-index=\"${index}\">${item.title}</div>`;\n })\n .join('');\n\n function switchUrl(index) {\n const itemOption = playlist[index];\n return player.switchUrl(itemOption.url, itemOption.title).then(() => {\n art.emit('artplayerPluginPlaylist:change', itemOption);\n });\n }\n\n function prevVideo() {\n const index = playlist.findIndex(item => item.url === $video.src);\n errorHandle(index !== -1, \"Can't find Playlist item\");\n if (playlist.length === 1) {\n return switchUrl(0);\n }\n const prevIndex = index - 1 === -1 ? playlist.length - 1 : index - 1;\n return switchUrl(prevIndex);\n }\n\n function nextVideo() {\n const index = playlist.findIndex(item => item.url === $video.src);\n errorHandle(index !== -1, \"Can't find Playlist item\");\n if (playlist.length === 1) {\n return switchUrl(0);\n }\n const nextIndex = index + 1 === playlist.length ? 0 : index + 1;\n return switchUrl(nextIndex);\n }\n\n proxy($playlistInner, 'click', e => {\n const { optionIndex } = e.target.dataset;\n if (optionIndex && Number(optionIndex) <= playlist.length - 1) {\n switchUrl(optionIndex);\n }\n });\n\n proxy($playlist, 'click', e => {\n if (e.target === $playlist) {\n $player.classList.remove('artplayer-playlist-show');\n }\n });\n\n art.on('video:ended', () => {\n nextVideo().then(() => {\n sleep(1000).then(() => {\n player.play = true;\n });\n });\n });\n\n art.on('afterAttachUrl', () => {\n const index = playlist.findIndex(item => item.url === $video.src);\n const $item = Array.from($playlistInner.children)[index];\n if (index !== -1 && $item) {\n inverseClass($item, 'active');\n }\n });\n\n return {\n name: 'artplayerPluginPlaylist',\n show() {\n $player.classList.add('artplayer-playlist-show');\n },\n hide() {\n $player.classList.remove('artplayer-playlist-show');\n },\n next() {\n nextVideo();\n },\n prev() {\n prevVideo();\n },\n };\n };\n}\n\nexport default artplayerPluginPlaylist;\n"],"names":["artplayerPluginPlaylist","list","art","constructor","utils","append","errorHandle","sleep","inverseClass","player","proxy","events","template","$player","$video","$playlist","Array","isArray","length","playlist","map","item","url","title","$playlistInner","querySelector","innerHTML","index","join","switchUrl","itemOption","then","emit","prevVideo","findIndex","src","prevIndex","nextVideo","nextIndex","e","optionIndex","target","dataset","Number","classList","remove","on","play","$item","from","children","name","show","add","hide","next","prev"],"mappings":";;;;;;IAEA,SAASA,uBAAT,CAAiCC,IAAjC,EAAuC;IACnC,SAAO,UAAAC,GAAG,EAAI;IAAA,gCAGNA,GAAG,CAACC,WAHE,CAENC,KAFM;IAAA,QAEGC,MAFH,yBAEGA,MAFH;IAAA,QAEWC,WAFX,yBAEWA,WAFX;IAAA,QAEwBC,KAFxB,yBAEwBA,KAFxB;IAAA,QAE+BC,YAF/B,yBAE+BA,YAF/B;IAAA,QAKNC,MALM,GAQNP,GARM,CAKNO,MALM;IAAA,QAMIC,KANJ,GAQNR,GARM,CAMNS,MANM,CAMID,KANJ;IAAA,wBAQNR,GARM,CAONU,QAPM;IAAA,QAOMC,OAPN,iBAOMA,OAPN;IAAA,QAOeC,MAPf,iBAOeA,MAPf;IAUV,QAAMC,SAAS,GAAGV,MAAM,CACpBQ,OADoB,mJAAxB;IASAP,IAAAA,WAAW,CAACULine truncated