current position:Home>Preliminary research on video
Preliminary research on video
2022-04-29 20:33:26【Twoyoung】
Preface :
Due to the use of video.js Of vue-video-player plug-in unit ; So the research is not limited to vue-video-player act ; It also includes video basics , plug-in unit video.js as well as Native Label at mobile end (android And ios) The performance of the ;
1. Video Basics :
2. Application in project :
Two ways :
2.1 stay HTML of use data-setup
<video data-setup='{ "autoplay": false, "preload": "auto" }'...>
Copy code
2.2 video.js of use options The ginseng
// videojs options
options: {
// muted: true, // Mute playback or not
autoplay: false, // Whether the player will play automatically when it is ready
loop: false, // Loop Playback
liveui: true,
preload: 'metautoadata',
language: 'en',
playbackRates: [0.5, 1.0, 1.5, 2.0], // Broadcasting speed
aspectRatio: '16:9', // Video adaptation ratio
fluid: true, // The player zooms to fit its container
bigPlayButton: true, // Big play button in the middle of the video
// flash: {
// swf: 'video-js-fixed.swf'
// },
controlBar:{ // Set whether to display the component
'currentTimeDisplay': true, // current time
'timeDivider':true, // Time divider
'durationDisplay':true, // The duration shows
'remainingTimeDisplay':true, // The remaining time shows
'volumeMenuButton': {
inline: true,// set volume bar For the level
vertical: false// set volume bar Is vertical
}
},
// Video stream resource set
sources: [{
type: "video/mp4",
src: 'https://xxx.com/video/ Industrial injury insurance advertisement .mp4'
}],
notSupportedMessage: ' This video can't be played , Please try again later ' // Allow to override Video.js The default information displayed when the media source cannot be played
// Play the previous video
poster: 'https://xxx.com/upload/82.png',
// Control button display sequence ( Component sequence )
// children: ['playToggle', 'volumeMenuButton', 'currentTimeDisplay', 'timeDivider', 'durationDisplay', 'progressControl', 'liveDisplay', 'remainingTimeDisplay', 'customControlSpacer', 'playbackRateMenuButton', 'chaptersButton', 'subtitlesButton', 'captionsButton', 'fullscreenToggle']
},
Copy code
2.3 vue Support in :
vue References in are based on video.js Of vue-video-player plug-in unit
// How to use local registration
<template>
<video-player class="video-player-box"
ref="videoPlayer"
:options="playerOptions"
:playsinline="true"
customEventName="customstatechangedeventname"
@play="onPlayerPlay($event)"
@pause="onPlayerPause($event)"
@ended="onPlayerEnded($event)"
@waiting="onPlayerWaiting($event)"
@playing="onPlayerPlaying($event)"
@loadeddata="onPlayerLoadeddata($event)"
@timeupdate="onPlayerTimeupdate($event)"
@canplay="onPlayerCanplay($event)"
@canplaythrough="onPlayerCanplaythrough($event)"
@statechanged="playerStateChanged($event)"
@ready="playerReadied">
</video-player>
</template>
<script>
import 'video.js/dist/video-js.css'
import { videoPlayer } from 'vue-video-player'
export default {
components: { videoPlayer },
data() {
return {
playerOptions: {
// videojs options
muted: true,
language: 'en',
playbackRates: [0.5, 1.0, 1.5, 2.0],
sources: [{
type: "video/mp4",
src: "http://cdn.moji.com/websrc/video/spring20200311.mp4"
}],
poster: "/static/images/author.jpg",
}
}
},
mounted() {
console.log('this is current player instance object', this.player)
},
computed: {
player() {
return this.$refs.videoPlayer.player
}
},
methods: {
// listen event
onPlayerPlay(player) {
// console.log('player play!', player)
this.$refs.videoPlayer.player.play()
},
onPlayerPause(player) {
// console.log('player pause!', player)
},
// ...player event
// or listen state event
playerStateChanged(playerCurrentState) {
// console.log('player current update state', playerCurrentState)
},
// player is ready
playerReadied(player) {
console.log('the player is readied', player)
player.play()
// you can use it to do something...
// player.[methods]
}
}
}
</script>
Copy code
2.4 vue-video-player Plug in for
Player
PosterImage // Default cover
TextTrackDisplay
LoadingSpinner
BigPlayButton // Big play button
ControlBar // Control bar
PlayToggle // Play pause
FullscreenToggle // Full screen
CurrentTimeDisplay // Current playback time
TimeDivider
DurationDisplay
RemainingTimeDisplay // Play time remaining
ProgressControl // time axis
SeekBar
LoadProgressBar
PlayProgressBar
SeekHandle
VolumeControl // Volume control
VolumeBar
VolumeLevel
VolumeHandle
PlaybackRateMenuButton // Playback rate
Copy code
》》》 For a more detailed introduction, you can see the... At the end of the article 4.0 Refer to the official information given in the document ;
3. Start stepping on all kinds of pits :
3.1 The play() request was interrupted by a call to pause()
The player is executing play() Method is executed immediately after pause() Caused by ;
resolvent : In execution play() Add a timer when ;
setTimeout(() => {
$video.play();
}, 10 );
// I personally tested this method, and there was no effect , But let's record it here ....
// Finally, I changed the call play() The timing of , Adopted stay @ready Call the instantiated... In the callback player Instance to execute player.play() I won't make a mistake .
Copy code
3.2 autoPlay Auto play
programme :
To solve iOS Autoplay problem on , Please do not use videojs Option to automatically play video .
A way that doesn't work :
(1)
<video id="my-video-id" autoplay></video>
Copy code
(2)
videojs('my-video-id', {
"autoplay": true
});
Copy code
Instead, wait for the video object to load , Then trigger the playback operation :
videojs('my-video-id').ready(function() {
this.play();
});
perhaps :
SPA Set in
// player is ready initialization
playerReadied(player) {
// Actively call video playback API
console.log('---readied----')
player.play() // Active call play api
console.log('--- Perform playback ----')
},
Copy code
A、video Video playback trigger condition :
1、touch since chromeM55 Remove from gesture events after version ; The video cannot be played for the first time in touch start Medium trigger ;
2、touch end Follow click Gesture events have certain time overlap , The first playback of the video may be triggered , But it's not reliable ;
3、 The first playback of the video can be in click Medium trigger ;
videoBtn3.addEventListener('click', function (evt) {
video.play();
})
Copy code
4、 The first playback of the video cannot be performed in timer Triggered in response ;
videoBtn4.addEventListener('touchstart', function (evt) {
setTimeout(function(){
video.play();
},1000);
})
Copy code
5、 The first playback of the video cannot be performed in promise Trigger in callback ;
videoBtn5.addEventListener('touchstart', function (evt) {
fetch('./video_gesture.html')
.then(function(response) {
video.play();
})
.catch(function(myBlob) {
video.play();
});
})
Copy code
B、 Other causes :
1、chrome6 And later versions do not allow automatic media playback ;
2、safari Prevent autoplay of video .opera prevent autoplay;
3、 For user experience , Consideration of saving traffic , Automatic playback is prohibited on the mobile terminal ;
4、 The video file is too large , Loading time is too long or error ;
C、 summary :
1. After adjusting all the above strategies ,IOS It can basically realize automatic playback , But set the mute , namely : No audio track , Or set up muted=true attribute .
2. Android's words , Only some models can play automatically . And you can't simulate autoplay , There must be user behavior ( Click the play button ) To trigger playback , In other words, the active behavior of users is stable .
3.3 Multi terminal playback behavior consistency processing
<video id="theVideo"
class="video-player"
preload="auto"
src="http://xxx"
type="video/mp4"
width="100%"
webkit-playsinline="true"
playsinline="true"
x5-video-player-type="h5"
x5-video-player-fullscreen="portraint"
x-webkit-airplay="true"
x5-playsinline=""></video>
Copy code
For adaptation iOS With Android , The last four attributes play a key role ;
webkit-playsinline="true";playsinline="true" The functions and iOS System , Use playsinline Prevent users from playing videos in full screen , No control attribute , Removed the control of the system , It is convenient to provide users with player controls written by themselves , Make different systems behave consistently .
x5- The first two properties , Acting on Android , Because the wechat browser kernel of Android system is X5,
x5-playsinline="";x5-video-player-type="h5";x5-video-player-fullscreen="landspace" These are two general configurations , Make the video horizontal Same layer mode Play .
3.4 Video coding ( Not in format ) This leads to the problem that some browsers play sound without picture
Problem description :
The progress bar can move with sound but no image . Under the baidu , Understand the relevant knowledge points ;
principle :
at present video Only tags are supported MP4,WebMail,Ogg Video format ;
Compatibility of major browsers with three video formats :
Format | IE | Firefox | Opera | Chrome | Safari |
---|---|---|---|---|---|
MPEG 4 | 9.0+ | No | No | 5.0+ | 3.0+ |
WebM | No | 4.0+ | 10.6+ | 6.0+ | No |
Ogg | No | 3.5+ | 10.5+ | 5.0+ | No |
MP4 = MPEG4 Files use H264 Video codec and AAC Audio codec
WebM = WebM Files use VP8 Video codec and Vorbis Audio codec
Ogg = Ogg Files use Theora Video codec and Vorbis Audio codec
Copy code
among MP4 Yes 3 Kind of code ,MPEG4(DivX)、MPEG4(Xvid)、AVC(H264); But only H264 Is recognized MP4 Standard coding .
Solution :
download “ Format Factory ”, Change the code in the output configuration to AVC(H264) , Export video , Upload the server again , Get it done !!!;
3.5 Video resources cannot be loaded properly
problem :
The media could not be loaded, either because the server or network failed or because the format is not supported
Copy code
screening :
When investigating this problem, you can follow the following steps to eliminate the cause in turn :
1、 verify video Of url Is there a wrong address ;
2、 Verify where the user is online ( There may be restrictions in some areas , For example, Xinjiang 、 Tibet );
3、 Verify the user's online environment , Is it a home network or a company network , If it's a home network , Let the user restart the router . If it's a corporate network , Let the user ask the company network management whether to ban the relevant protocol ;
4、 If it is not possible to determine whether the connected network forbids the relevant protocol , Users can be advised to use the computer to connect to the mobile phone hotspot before trying to play , If you can play it after connecting the hotspot of the mobile phone , It must be that the video protocol has been banned ;
5、MP4 Video format coding problems , see 2.4.
4. Reference documents :
vue-video-player file : https://github.com/surmon-china/vue-video-player
video.js file : docs.videojs.com/tutorial-op…
tencent X5 Official explanation of kernel video behavior : x5.tencent.com/tbs/guide/v…
video.js Problems encountered in : www.cnblogs.com/loveamyfore…
About MediaSource: https://developer.mozilla.org/zh-CN/docs/Web/API/MediaSource
copyright notice
author[Twoyoung],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/04/202204292033194175.html
The sidebar is recommended
- Talking about nodejs server
- Node. js&lt; I & gt—— Encounter node and repl usage
- Vue basic API: calculation attribute + filter + listener
- 1-stm32 + mn316 (nb-iot) remote upgrade OTA (self built Internet of things platform) - STM32 uses HTTP to download program files and upgrade programs through mn316 (MCU program rotation check and update)
- Vue Axios response interception
- vue3 ref
- How does Vue transfer the data from the parent component to the child component intact?
- The back-end interface developed by springboot in idea and the Vue front-end developed by vscode. How to integrate Vue code into springboot?
- Fried cold rice series 4: scope and closure in JavaScript
- Typescript type compatibility learning
guess what you like
Summary of bugs encountered in front-end development
Chrome developer tool: performance analysis using web panel
Collation of common semantic elements and global attributes in HTML
Life cycle in Vue
5.1 fear of traffic jam? With a budget of less than 100000, these cars with adaptive cruise make it easy for you to travel
Docker compose deploy nginx configure SSL
The content of element type “mapper“ must match “(cache-ref|cache|resultMap*|parameterMap*|sql*|inse
-CSS-
Vue uses two-way binding to implement the user registration page
Is Infiniti qx60 worth less than 400000 yuan? It depends on the discount
Random recommended
- "Element Fangjian: first heart version" public beta welfare release, go to the great God app to receive red envelopes and prizes
- What is the role of webpack cli in webpack packaging
- Vue3 configuration method using Axios
- How to configure Google reverse proxy on nginx server
- Volume comparison between Vue and react
- What are the three ways to define components in react
- How to install and configure the blogging program Typecho on the nginx server
- How to configure load balancing for TCP in nginx server
- How to configure nginx server under Windows system
- How to configure AB to do stress testing for nginx server
- Analysis of location configuration in nginx server
- How to integrate Linux and redmine into the redmine system
- How to build the production environment of nginx + PHP with PHP FPM
- How to optimize the performance of nginx supporting SSL
- How to configure nginx server to prevent flood attack
- [Axios learning] basic use of Axios
- [Axios learning] Axios request mode, concurrent request, global configuration, instance and interceptor
- Use the virtual queue implemented by list to view the first element of the queue in Python without taking it out
- This dependency was not found and to install it, you can run: NPM install score JS
- Front end serial communication
- leedcode. 203 remove linked list elements
- Dialogue with Liu Dayong, information director of Jiuyang shares: key elements of enterprise digital intelligence transformation
- JQuery gets the method summary of parent element, child element and brother element
- Web Security: analysis of DOM XSS vulnerability source code of jquery
- The sales volume of Genesys in China is 283, less than 300, and the domestic sales volume is dismal
- This beast was blessed with skills to test drive the DHT version of Harvard beast
- Bootstrap and jQuery implement tree structure
- Fried cold rice series 5: recursion in JavaScript?
- 2022 open source summer | serverless devs accompany you to "become stronger"
- How to create a high-performance full screen red envelope rain
- Detailed process of spring boot free HTTPS project configuration!
- Create a simple vue3 project
- How to create a simple react project
- Vue custom text background
- Front end HTML
- leetcode:462. Minimum number of moves to make array elements equal II [sort + find the middle]
- City selection (provincial and urban cascade) plug-in v-distpicker component details and a full set of usage
- How to use js to achieve such a drag and zoom effect
- Quick report ~ node JS 18 coming! Let's see what's new
- Easily manage projects using Vue UI graphical interface