Skip to content

Commit

Permalink
Configuration forceLive
Browse files Browse the repository at this point in the history
  • Loading branch information
huangqicong committed Apr 26, 2019
1 parent 743464b commit f73a375
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 8 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ parserOptions:
sourceType: module

env:
commonjs: true,
es6: true
browser: true

Expand Down
2 changes: 1 addition & 1 deletion dist/vue-mediaelement.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/vue-mediaelement.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions example/example.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</h4>
<mediaelement ref="vPlay" :autoplay="true" :forceLive="forceLive" preload="true" :source="selected" width="500px" height="500px"></mediaelement>
<button @click="close">关闭播放</button>
<button @click="live">切换进度</button>
</div>
</template>

Expand All @@ -22,6 +23,7 @@ export default {
return {
selected: 'https://d2zihajmogu5jn.cloudfront.net/bipbop-advanced/bipbop_16x9_variant.m3u8',
forceLive: false,
autoplay: true,
sources: [{
name: 'MP4',
value: 'http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4'
Expand Down Expand Up @@ -65,6 +67,9 @@ export default {
console.log(this.$refs.vPlay.Features('isIE'));
},
methods: {
live() {
this.forceLive = true;
},
close() {
console.log(this.$refs);
this.$refs.vPlay.remove();
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"extract-text-webpack-plugin": "4.0.0-beta.0",
"file-loader": "^3.0.1",
"style-loader": "^0.20.3",
"url-loader": "^1.1.2",
"vue": "2.5.16",
"vue-loader": "^14.2.2",
"vue-template-compiler": "2.5.16",
Expand Down
21 changes: 15 additions & 6 deletions src/mediaelement.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<template>
<video :height="height" :width="width" :autoplay="autoplay" :preload="preload" >
<video :height="height" :width="width" :autoplay="autoplay" :preload="preload">
</video>
</template>

<style>
@import '../node_modules/mediaelement/build/mediaelementplayer.min.css';
.mejs__container {
min-width: auto !important;
}
Expand Down Expand Up @@ -39,11 +40,12 @@ mediaelementwrapper object{
// import flvjs from 'flv.js';
// import hlsjs from 'hls.js';
import 'mediaelement';
import 'mediaelement/build/mediaelementplayer.min.css';
// import 'mediaelement/build/mediaelementplayer.min.css';
// import 'mediaelement/build/mediaelement-flash-video.swf';
// import 'mediaelement/build/mediaelement-flash-video-hls.swf';
export default {
name: 'mediaelement',
props: {
source: {
type: String,
Expand Down Expand Up @@ -89,6 +91,7 @@ export default {
}
},
data: () => ({
refresh: false,
player: null,
}),
mounted() {
Expand All @@ -104,13 +107,13 @@ export default {
// (by default, this is set as `sameDomain`)
// shimScriptAccess: 'always',
success: (mediaElement, originalNode, instance) => {
instance.setSrc(componentObject.source);
if (componentObject.autoplay) {
instance.setSrc(componentObject.source);
mediaElement.addEventListener('canplay', function () {
instance.play();
});
}
this.success(mediaElement, originalNode, instance);
mediaElement.addEventListener('canplay', function () {
instance.play();
});
// mediaElement.addEventListener(Hls.Events.MEDIA_ATTACHED, function () {
// // All the code when this event is reached...
// console.log('Media attached!');
Expand Down Expand Up @@ -142,6 +145,12 @@ export default {
this.player.setSrc(newSource);
this.player.setPoster('');
this.player.load();
},
forceLive: function (newForceLive, oldForceLive) {
if (newForceLive === oldForceLive) {
return;
}
this.player.options.forceLive = newForceLive;
}
},
};
Expand Down
8 changes: 8 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ module.exports = {
test: /\.(png|jpg|gif|svg|swf)$/,
loader: 'file-loader?name=[name].[ext]'
}
// {
// test: /\.(png|jpg|gif|svg|swf)$/,
// loader: 'url-loader',
// options: {
// limit: 10000,
// name: '[name].[ext]',
// },
// }
]
},
plugins: [
Expand Down

0 comments on commit f73a375

Please sign in to comment.