Commit 25967b8337fa36df7ba0def9b3a5f249b4d24255
1 parent
f05b08a2
播放功能
Showing
1 changed file
with
53 additions
and
3 deletions
src/pages/index/index.vue
| @@ -11,7 +11,15 @@ | @@ -11,7 +11,15 @@ | ||
| 11 | </div> | 11 | </div> |
| 12 | </div> | 12 | </div> |
| 13 | <!--视频--> | 13 | <!--视频--> |
| 14 | - <div></div> | 14 | + <div> |
| 15 | + <video-player class="video-player vjs-custom-skin" @play="onPlayerPlay($event)" | ||
| 16 | + ref="videoPlayer" | ||
| 17 | + :playsinline="playsinline" | ||
| 18 | + :options="playerOptions" | ||
| 19 | + x5-playsinline | ||
| 20 | + webkit-playsinline> | ||
| 21 | + </video-player> | ||
| 22 | + </div> | ||
| 15 | 23 | ||
| 16 | <div></div> | 24 | <div></div> |
| 17 | 25 | ||
| @@ -46,15 +54,57 @@ | @@ -46,15 +54,57 @@ | ||
| 46 | </template> | 54 | </template> |
| 47 | 55 | ||
| 48 | <script> | 56 | <script> |
| 57 | + import { videoPlayer } from 'vue-video-player'; | ||
| 58 | + import 'video.js/dist/video-js.css'; | ||
| 59 | + import '../../../static/css/video.css'; | ||
| 49 | export default { | 60 | export default { |
| 50 | name: 'index', | 61 | name: 'index', |
| 51 | data () { | 62 | data () { |
| 52 | - return {} | 63 | + return { |
| 64 | + playsinline: true, | ||
| 65 | + playerOptions: { | ||
| 66 | + events: [], | ||
| 67 | + playbackRates: [0.5, 1.0, 1.5, 2.0], // 播放速度 | ||
| 68 | + autoplay: false, // 如果true,浏览器准备好时开始回放。 | ||
| 69 | + controls: true, // 控制条 | ||
| 70 | + preload: 'auto', // 视频预加载 | ||
| 71 | + muted: false, // 默认情况下将会消除任何音频。 | ||
| 72 | + loop: false, // 导致视频一结束就重新开始。 | ||
| 73 | + language: 'zh-CN', | ||
| 74 | + controlBar: { | ||
| 75 | + timeDivider: true, | ||
| 76 | + durationDisplay: true | ||
| 77 | + }, | ||
| 78 | + aspectRatio: '16:9', // 将播放器置于流畅模式,并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字(例如"16:9"或"4:3") | ||
| 79 | + fluid: true, // 当true时,Video.js player将拥有流体大小。换句话说,它将按比例缩放以适应其容器。 | ||
| 80 | + sources: [], | ||
| 81 | + hls: true, // 启用hls? | ||
| 82 | + poster: '../../../static/img/index/15.jpg', // 你的封面地址 | ||
| 83 | + width: document.documentElement.clientWidth || document.body.clientWidth, | ||
| 84 | + notSupportedMessage: '此视频暂无法播放,请稍后再试' // 允许覆盖Video.js无法播放媒体源时显示的默认信息。 | ||
| 85 | + }, | ||
| 86 | + } | ||
| 87 | + }, | ||
| 88 | + components:{ | ||
| 89 | + videoPlayer | ||
| 53 | }, | 90 | }, |
| 54 | created(){ | 91 | created(){ |
| 55 | 92 | ||
| 56 | }, | 93 | }, |
| 57 | - methods: {} | 94 | + methods: { |
| 95 | + /** | ||
| 96 | + * 视频播放 | ||
| 97 | + * @param {object} $event [播放器对象] | ||
| 98 | + */ | ||
| 99 | + onPlayerPlay($event) { | ||
| 100 | + if(this.isiPhone.value && window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.CNDSPlayer) { | ||
| 101 | + window.webkit.messageHandlers.CNDSPlayer.postMessage({body: { | ||
| 102 | + playUrl: this.playerOptions.sources[0].src, // 视频URL | ||
| 103 | + isLive: 0 // 0录播1直播 | ||
| 104 | + }}); | ||
| 105 | + } | ||
| 106 | + }, | ||
| 107 | + } | ||
| 58 | } | 108 | } |
| 59 | </script> | 109 | </script> |
| 60 | 110 |