GoEasyVideoPlayer.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <video
  3. v-if="show"
  4. class="video-player"
  5. controls = ""
  6. @play="onPlayStart"
  7. id="videoPlayer"
  8. autoplay="true"
  9. @error="error"
  10. @fullscreenchange="onVideoFullScreenChange"
  11. :src="url">
  12. </video>
  13. </template>
  14. <script>
  15. export default {
  16. name: "GoEasyVideoPlayer",
  17. data () {
  18. return {
  19. show : false,
  20. context: null,
  21. url: ''
  22. }
  23. },
  24. methods : {
  25. play (video) {
  26. this.url = video.url;
  27. this.context = uni.createVideoContext('videoPlayer');
  28. this.show = true;
  29. },
  30. onVideoFullScreenChange (e) {
  31. //当退出全屏播放时,隐藏播放器
  32. if(this.show && !e.detail.fullScreen){
  33. this.show = false;
  34. this.context.stop();
  35. }
  36. },
  37. onPlayStart () {
  38. //播放开始时,立即全屏
  39. this.context.requestFullScreen({
  40. direction : 0
  41. });
  42. },
  43. error (e) {
  44. console.log(e)
  45. }
  46. }
  47. }
  48. </script>
  49. <style scoped>
  50. .video-player{
  51. position: fixed;
  52. top: 0;
  53. left: 0;
  54. right: 0;
  55. bottom: 0;
  56. }
  57. </style>