playVideo.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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" @error="videoErrorCallback"></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. /* uni.downloadFile({
  74. url: "https://samplelib.com/lib/preview/mp4/sample-5s.mp4",
  75. success: (res) => {
  76. if (res.statusCode === 200) {
  77. uni.saveVideoToPhotosAlbum({
  78. filePath: res.tempFilePath
  79. })
  80. // 提示用户下载成功
  81. uni.showToast({
  82. title: "下载成功",
  83. icon: "success"
  84. });
  85. }
  86. else {
  87. uni.showToast({
  88. title: "资源格式错误,请联系管理员"
  89. });
  90. }
  91. },
  92. fail: (err) => {
  93. uni.hideLoading();
  94. uni.showToast({
  95. title: "下载失败",
  96. icon:'error'
  97. })
  98. }
  99. }) */
  100. },
  101. shareToggle() {
  102. this.$refs.share.open()
  103. },
  104. shareWeibo() {
  105. uni.share({
  106. provider: "sinaweibo",
  107. type: 4,
  108. mediaUrl: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/2minute-demo.mp4",
  109. success: function(res) {
  110. console.log("success:" + JSON.stringify(res));
  111. },
  112. fail: function(err) {
  113. console.log("fail:" + JSON.stringify(err));
  114. }
  115. });
  116. },
  117. shareWechat() {
  118. uni.share({
  119. provider: "weixin",
  120. scene: "WXSceneSession",
  121. type: 4,
  122. mediaUrl: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/2minute-demo.mp4",
  123. success: function(res) {
  124. console.log("success:" + JSON.stringify(res));
  125. },
  126. fail: function(err) {
  127. console.log("fail:" + JSON.stringify(err));
  128. }
  129. });
  130. },
  131. shareTimeline() {
  132. uni.share({
  133. provider: "weixin",
  134. scene: "WXSceneTimeline",
  135. type: 4,
  136. mediaUrl: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/2minute-demo.mp4",
  137. success: function(res) {
  138. console.log("success:" + JSON.stringify(res));
  139. },
  140. fail: function(err) {
  141. console.log("fail:" + JSON.stringify(err));
  142. }
  143. });
  144. }
  145. }
  146. }
  147. </script>
  148. <style scoped lang="scss">
  149. .video-player-container {
  150. .video-player {
  151. width: 100%;
  152. height: 300px;
  153. }
  154. .icon-area {
  155. display: flex;
  156. justify-content: space-evenly;
  157. margin-top: 50px;
  158. }
  159. .popup-content {
  160. width: 100%;
  161. height: 150px;
  162. display: flex;
  163. flex-direction: column;
  164. align-items: center;
  165. .text {
  166. margin: 10px 0;
  167. font-size: 20px;
  168. }
  169. .app-icon {
  170. display: flex;
  171. justify-content: space-between;
  172. margin: 10px 0;
  173. .app-icon-item {
  174. width: 100px;
  175. display: flex;
  176. flex-direction: column;
  177. align-items: center;
  178. .app-icon-img {
  179. width: 30px;
  180. height: 30px;
  181. }
  182. .app-icon-text {
  183. margin-top: 10px;
  184. text-align: center;
  185. }
  186. }
  187. }
  188. }
  189. }
  190. </style>