時間:2023-03-18來源:系統城裝機大師作者:佚名
最近閑來無事,在自己的小程序里面集成了一個小視頻的接口,但是由于小程序對于播放視頻的限制,只能用來做一個demo刷視頻了,沒辦法上線體驗。
小程序播放視頻限制最多10個,超出可能就崩了。
我也有想過用js去追加和刪減,但是還是有點麻煩了,等有空了再把想法化為現實吧。
uniapp
項目里面的 pages.json
文件中修改當前頁面路徑的 navigationStyle
1 2 3 4 5 6 7 8 |
{ "path" : "pages/searchvideo/searchvideo" , "style" : { "navigationBarTitleText" : "小視頻" , "enablePullDownRefresh" : false , "navigationStyle" : "custom" } } |
頂部欄可以根據自己的需求自定義,我這里放了一個類似于抖音的 tab欄
。
在uniapp
和原生的微信小程序
里面都有 swiper
標簽用于做滾動或輪播效果的組件,所以我們可以直接利用這個組件做出我們想要的效果。
1 2 3 4 5 6 7 8 |
< swiper class = "card-swiper" :circular = "true" vertical = "true" :autoplay = "true" duration = "500" interval = "5000" @ change = "cardSwiper" > < swiper-item v-for = "(item,index) in swiperList" :key = "index" :class = "cardCur==index?'cur':''" > < view class = "swiper-item image-banner" > < video :id = "`video-${item.id}`" :src = "item.mp4" loop style = "height: 100vh;width: 100vw;" ></ video > </ view > </ swiper-item > </ swiper > |
autoplay
元素,可以讓頁面打開時,不會自動播放視頻。duration
的值,需要等于當前視頻的播放時長。swiperList
的數據,方便我們操作當前視頻。1 2 3 4 5 6 7 8 9 10 11 |
cardCur: 0, swiperList: [{ id: 0, mp4: 'http://vcdnb.huoying666.com/new_video/2022/0725/b94a235358c31668dc99e7cff9fe5e9c/v1080/b94a235351_6921661_fhd.mp4' }, { id: 1, mp4: 'http://vcdnb.huoying666.com/new_video/2020/1211/9d0b01c88bd05721f9de88122de72db1/v1080/9d0b01c881_5872976_fhd.mp4' }, { id: 2, mp4: 'http://vcdnb.huoying666.com/new_video/2021/1109/6f5610c304083ca59141c8f70aca6396/v720/6f5610c301_6578243_hd.mp4' }] |
data
中定義 swiperList
數據內容,當然你也可以做成接口形式動態添加進去。cardCur
的默認值,用于配置視頻滾動下標。1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
.card-swiper { height : 100 vh !important ; } .card-swiper swiper-item { width : 750 rpx !important ; left : 0 rpx; box-sizing: border-box; overflow : initial; } .card-swiper swiper-item .swiper-item { width : 100% ; display : block ; height : 100 vh; border-radius: 0 rpx; transform: scale( 1 ); transition: all 0.2 s ease-in 0 s; overflow : hidden ; } .card-swiper swiper-item.cur .swiper-item { transform: none ; transition: all 0.2 s ease-in 0 s; } .card-swiper swiper-item .swiper-item-png { margin-top : -50 vh; width : 100% ; display : block ; border-radius: 0 rpx; transform: translate( 1040 rpx, 20 rpx) scale( 0.5 , 0.5 ); transition: all 0.6 s ease 0 s; } .card-swiper swiper-item.cur .swiper-item-png { margin-top : -100 vh; width : 900 rpx; transform: translate( -80 rpx, 0 rpx) scale( 1 , 1 ); transition: all 0.6 s ease 0 s; } .image-banner { display : flex; align-items: center ; justify- content : center ; } .image-banner image { width : 100% ; } |
1 2 3 4 5 6 7 8 9 10 11 |
cardSwiper(e) { this .cardCur = e.detail.current for (let i = 0; i < this .swiperList.length; i++) { const videoContext = uni.createVideoContext(`video-${ this .swiperList[i][ 'id' ]}`, this ) if (i === this .cardCur) { videoContext.play() } else { videoContext.stop() } } } |
methods
中定義 swiper
改變時的方法,用于控制視頻的暫停和播放。由于uniapp
是可以直接編譯成 H5
的,所以我們就直接在掘金代碼片段
中看一下效果吧。
代碼片段里面的內容是直接引用的uniapp云發布的鏈接,如果想了解這一塊的內容,可以單獨開篇文章寫一下的。
1 2 3 |
< div id = "app" > < iframe src = "https://static-54d8ac48-ba3d-4f0d-8a0b-029cbc34a4b3.bspapp.com/#/" width = "400" height = "800" ></ iframe > </ div > |
{"success":false,"error":{"code":"InvalidSpace.Deleted","message":"The space is already deleted."},"data":null}
這個功能對于小程序來說做起來不算太復雜,也是由于微信的限制,不能做出太復雜的刷視頻的功能。大家可以根據自己的需求去修改這一塊的代碼
2023-03-18
ChatGPT在前端領域的初步探索2023-03-18
Vue.js React與Angular流行前端框架優勢對比2023-03-18
threeJs實現波紋擴散及光標浮動效果詳解假如某個新開發的功能,要新增10張表,按照這個時間計算,至少要100分鐘,仔細想想,其實你會發現大部分的時間都浪費在這些簡單而又重復的編程圈子中去了。那有沒有一個辦法,將這些簡...
2023-03-15
二、Keil下載和安裝教程 三、注冊教程 1、以管理員身份運行Keil uVision5(必須要以管理員身份運行) 2、點擊右上角File,再點擊License Managment 3、復制CID 4、以管理員身份運行keygen.exe(必須使用管理員身份運行) 5、Ta...
2023-03-15