playVideo.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <view class="video-player-container">
  3. <view>
  4. <video class="video-player" controls @play.prevent id="myVideo"
  5. src="@/static/videos/86e914d805fe8578f8258d21eeac7ddc.mp4"></video>
  6. </view>
  7. <view class="icon-area">
  8. <uni-icons type="download-filled" size="30" color="#BD3124" @click="downloadVideo"></uni-icons>
  9. <uni-icons type="redo-filled" size="30" color="#BD3124" @click="shareToggle"></uni-icons>
  10. </view>
  11. <uni-popup ref="share" type="share" safeArea backgroundColor="#fff">
  12. <view class="popup-content">
  13. <text class="text">分享到</text>
  14. <view class="app-icon">
  15. <view class="app-icon-item" @click="shareWeibo">
  16. <image class="app-icon-img" src="@/static/images/xijiao/weibo.png"></image>
  17. <view class="app-icon-text">
  18. 新浪微博
  19. </view>
  20. </view>
  21. <view class="app-icon-item" @click="shareWechat">
  22. <image class="app-icon-img" src="@/static/images/xijiao/WeChat.png"></image>
  23. <view class="app-icon-text">
  24. 微信
  25. </view>
  26. </view>
  27. <view class="app-icon-item" @click="shareTimeline">
  28. <image class="app-icon-img" src="@/static/images/xijiao/timeline.png"></image>
  29. <view class="app-icon-text">
  30. 朋友圈
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. </uni-popup>
  36. </view>
  37. </template>
  38. <script>
  39. export default {
  40. data() {
  41. return {
  42. isLoading:false,
  43. }
  44. },
  45. methods: {
  46. downloadVideo() {
  47. uni.showToast({
  48. title: "下载中",
  49. icon: "loading",
  50. duration:100000
  51. })
  52. uni.downloadFile({
  53. url: 'https://samplelib.com/lib/preview/mp4/sample-5s.mp4',
  54. success: (res) => {
  55. if (res.statusCode === 200) {
  56. console.log('下载成功');
  57. uni.hideToast()
  58. uni.saveVideoToPhotosAlbum({
  59. filePath: res.tempFilePath
  60. })
  61. uni.showToast({
  62. title: "下载成功",
  63. icon: "success"
  64. })
  65. }else{
  66. uni.showToast({
  67. title: "下载失败",
  68. icon: "error"
  69. })
  70. }
  71. }
  72. });
  73. },
  74. shareToggle() {
  75. this.$refs.share.open()
  76. },
  77. shareWeibo() {
  78. uni.share({
  79. provider: "sinaweibo",
  80. type: 4,
  81. mediaUrl: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/2minute-demo.mp4",
  82. success: function(res) {
  83. console.log("success:" + JSON.stringify(res));
  84. },
  85. fail: function(err) {
  86. console.log("fail:" + JSON.stringify(err));
  87. }
  88. });
  89. },
  90. shareWechat() {
  91. uni.share({
  92. provider: "weixin",
  93. scene: "WXSceneSession",
  94. type: 4,
  95. mediaUrl: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/2minute-demo.mp4",
  96. success: function(res) {
  97. console.log("success:" + JSON.stringify(res));
  98. },
  99. fail: function(err) {
  100. console.log("fail:" + JSON.stringify(err));
  101. }
  102. });
  103. },
  104. shareTimeline() {
  105. uni.share({
  106. provider: "weixin",
  107. scene: "WXSceneTimeline",
  108. type: 4,
  109. mediaUrl: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/2minute-demo.mp4",
  110. success: function(res) {
  111. console.log("success:" + JSON.stringify(res));
  112. },
  113. fail: function(err) {
  114. console.log("fail:" + JSON.stringify(err));
  115. }
  116. });
  117. }
  118. }
  119. }
  120. </script>
  121. <style scoped lang="scss">
  122. .video-player-container {
  123. .video-player {
  124. width: 100%;
  125. height: 300px;
  126. }
  127. .icon-area {
  128. display: flex;
  129. justify-content: space-evenly;
  130. margin-top: 50px;
  131. }
  132. .popup-content {
  133. width: 100%;
  134. height: 150px;
  135. display: flex;
  136. flex-direction: column;
  137. align-items: center;
  138. .text {
  139. margin: 10px 0;
  140. font-size: 20px;
  141. }
  142. .app-icon {
  143. display: flex;
  144. justify-content: space-between;
  145. margin: 10px 0;
  146. .app-icon-item {
  147. width: 100px;
  148. display: flex;
  149. flex-direction: column;
  150. align-items: center;
  151. .app-icon-img {
  152. width: 30px;
  153. height: 30px;
  154. }
  155. .app-icon-text {
  156. margin-top: 10px;
  157. text-align: center;
  158. }
  159. }
  160. }
  161. }
  162. }
  163. </style>