When the existing video player cannot meet the needs, you need to encapsulate the video yourself. Video Events
Live Broadcast Protocol HLS (HTTP Live Streaming) is a live streaming protocol proposed by Apple. Both iOS and higher versions of Android support HLS. HLS mainly consists of two playback files: .m3u8 and .ts. HLS has high compatibility and scalability, but it will cause live broadcast delay. The HLS protocol divides the live stream into small segments for download and playback. So assuming that the list contains 5 ts files and each ts file contains 5 seconds of video content, the overall delay is 25 seconds. RTMP (Real Time Messaging Protocol) is a set of live video protocols developed by Macromedia, which now belongs to Adobe. RTMP is based on flash and cannot be played in iOS browsers, but its real-time performance is better than HLS. HTTP-FLV is a live distribution stream for FLV video format with low latency. But it is not supported on mobile devices. Conclusion: HTTP-FLV has low latency and is preferred. If the device does not support HTTP-FLV, use flv.js. If the device does not support flv.js, HLS is used, but HLS has a large delay. Encapsulating video/** HTML **/ <div class="video"> <!-- video player --> <video class="video__player" ref="videoPlayer" preload="auto" :autoplay="options.autoplay" :muted="options.muted" webkit-playsinline="true" playsinline="true" x-webkit-airplay="allow" x5-video-player-type="h5-page" x5-video-orientation="portraint" style="object-fit:cover;" > <source :src="options.src" /> </video> <!-- video poster --> <div v-show="showPoster" class="video__poster" :style="{'background-image': 'url(' + options.pic + ')'}" ></div> <!-- video loading --> <div v-show="showLoading" class="video__Loading"> <span class="video__Loading-icon"></span> </div> <!-- video pause --> <div @click="handleVideoPlay" class="video__pause"> <span v-show="!videoPlay" class="video__pause-icon"></span> </div> </div> /**js**/ props: { options: type: Object, default: () => {} } }, data() { return { videoPlay: false, // Is the video currently playing videoEnd: false, // Has the video ended? showPoster: true, // Is the video cover displayed? showLoading: false, // Loading currentTime: 0, // Current playback position currentVideo: { duration: this.options.duration }, } }, mounted() { this.videoPlayer = this.$refs.videoPlayer; this.videoPlayer.currentTime = 0; this.videoPlayer.addEventListener("loadstart", e => { this.videoPlayer.currentTime = (this.options.playProcess > 0) ? this.options.playProcess : 0; }); // Get the video length this.videoPlayer.addEventListener("durationchange", e => { this.currentVideo.duration = this.videoPlayer.duration; // Playback history exists this.videoPlayer.currentTime = (this.options.playProcess > 0) ? this.options.playProcess : 0; }); this.videoPlayer.addEventListener("playing", e => { this.showPoster = false; this.videoPlay = true; this.showLoading = false; this.videoEnd = false; }); // Pause this.videoPlayer.addEventListener("pause", () => { this.videoPlay = false; if (this.videoPlayer.currentTime < 0.1) { this.showPoster = true; } this.showLoading = false; }); // Playback progress update this.videoPlayer.addEventListener("timeupdate", e => { this.currentTime = this.videoPlayer.currentTime; }, false ); // Specify the playback position this.videoPlayer.addEventListener("seeked", e => { }); // Buffering this.videoPlayer.addEventListener("waiting", e => { this.showLoading = true; }); // Playback ends this.videoPlayer.addEventListener("ended", e => { // Reset state this.videoPlay = false; this.showPoster = true; this.videoEnd = true; this.currentTime = this.currentVideo.duration; }); // Listen for the weixinJSBridgeReady event to handle the problem of WeChat not being able to play automatically. But it is not applicable to all of them. A pause button is added for manual playback. document.addEventListener('WeixinJSBridgeReady', () => { this.videoPlayer.play(); }, false); }, methods: { handleVideoPlay() { if (this.videoPlayer.paused) { // Play if (this.videoEnd) { // Replay this.currentTime = 0; this.videoPlayer.currentTime = 0; } this.videoPlayer.play(); this.videoPlay = true; } else { // Pause this.videoPlayer.pause(); this.videoPlay = false; } } } [Reference Article]:
This is the end of this article about the implementation example of the vue-based video player. For more relevant vue video player content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of configuring keepalived log to another path in centos7
>>: Instances of excluding certain libraries when backing up the database with mysqldump
Using iframes can easily call pages from other we...
First you need to install Vue-cli: npm install -g...
ins and del were introduced in HTML 4.0 to help au...
Below are some common parameters of /etc/my.cnf o...
1. Commonjs Commonjs is a custom module in nodejs...
In-depth understanding of this in Js JavaScript s...
Table of contents 1. Responsive principle foundat...
You may not have had any relevant needs for this ...
The best thing you can do for your data and compu...
Preface You should often see this kind of special...
Background Here's what happened, Luzhu accide...
KILL [CONNECTION | QUERY] processlist_id In MySQL...
Table of contents 1. Download steps 2. Configure ...
Nginx's rewrite function supports regular mat...
Copy code The code is as follows: jQuery.cookie =...