在線播放+彈幕】作者HustWolf開篇語前幾天發了一篇練手文章,不出意外地火了:《簡年15: 微信小程序(有始有終,全部代碼)開發---跑步App+音樂播放器 》后來 ... ... ...
今天本來想就此罷手,但是沒辦法,手癢難耐,所以又加了個在線放視頻的功能。同時調整了下以前的一些代碼,比如一些的UI設計增進了。
.WXSS
文件也被我豐富了一點點。那些不影響功能的我就沒有細說了,代碼已經全部更新于Github,歡迎大家去查看:
https://github.com/HustWolfzzb/WeChat-Fucking_Running.git
更新之后的頁面更加漂亮了。當然,功能也稍微提高了點:
更新的代碼如下,是在
app.json
這個文件下作的更改:
"window":{
"backgroundTextStyle":"black",
"navigationBarBackgroundColor": "#ffddae",
"navigationBarTitleText": "Running Man",
"navigationBarTextStyle":"black"
},
"tabBar": {
"list": [{
"pagePath": "pages/index",
"backgroundColor": "#adddaa",
"iconPath":"/resources/yan1.jpg",
"selectedIconPath":"/resources/yan1.jpg"
}, {
"pagePath": "pages/logs/logs",
"iconPath":"/resources/yan2.jpg",
"selectedIconPath":"/resources/yan2.jpg"
}
],
"color": "#ad8888",
"backgroundColor": "#fdfdae"
}
大家伙還記得我一直吐槽的莫名其妙的動畫界面嗎?現在算是廢物利用,我給它增開了一個組件,就是今天的主角--
video
。顧名思義,就是視頻播放。內容的話選擇了我比較喜歡的東京食尸鬼。不過由于第一季的畫質較高,轉碼估計要轉到我開學,所以我就選擇了畫質較差的第二季。但是手機用戶的觀看體驗應該也差不了多少。文件格式采用的是webm,也就是通用的web播放流媒體的視頻文件格式。
代碼更新如下:
<animation.js>
data:{
// Chapters:[1,2,3,4,5,6,7,8,9,10,11,12],
chapter:0
},
Next:function(){
this.setData(
{
chapter:this.data.chapter + 1
})
},
Last:function(){
this.setData(
{
chapter:this.data.chapter - 1
})
},
<animation.wxml>
<import src="../common/header.wxml" />
<import src="../common/footer.wxml" />
<label class="label" type="primary">東京食尸鬼第{{chapter}}集</label>
<video class="video" src="http://119.29.74.46/Dj/Dj_{{chapter}}.webm" objectFit="contain"></video>
<button bindtap="Last">上一集</button>
<button bindtap="Next">下一集</button>
<view class="container">
<!-- <template is="header" data="{{title: 'createAnimation'}}"/>
-->
<view class="page-body">
<view class="page-body-wrapper">
<view class="animation-element-wrapper">
<view class="animation-element" animation="{{animation}}"></view>
</view>
<view class="animation-buttons" scroll-y="true">
<button class="animation-button" bindtap="rotate">Rotate</button>
<button class="animation-button" bindtap="scale"> Scale</button>
<button class="animation-button" bindtap="translate">Translate</button>
<button class="animation-button" bindtap="skew">Skew</button>
<button class="animation-button" bindtap="rotateAndScale">Rotate&Scale</button>
<button class="animation-button" bindtap="rotateThenScale">Rotate-Scale</button>
<button class="animation-button" bindtap="all">All</button>
<button class="animation-button" bindtap="allInQueue">All~</button>
<button class="animation-button-reset" bindtap="reset">Reset</button>
<view class="page-body-info">上面分別是旋轉、縮放、移動、傾斜</view>
</view>
</view>
</view>
<template is="footer" />
</view>
本次更改,其實還是有問題殘留的,因為我暫時沒找到辦法獲取wxml文件中的數值傳到js文件中的辦法。大家可以看到上面的js文件中的data里面有一個Chapters被注釋了。我的本來的想法是利用wx:for="{{Chapters}}"來直接把所有的視頻鏈接做成按鈕放到頁面上去的。就類似下面的這樣:
很可惜的沒有成功回調wxml中的item的id,看我網上的大神說,利用wx:for-index可以回調id號,然后利用currentTarget.id;獲取id并導入js文件中,但是很可惜我并沒有成功。不過如果最后還是不行的話,可以采用蠢辦法:一個按鈕一個事件綁定的野路子。這樣不需要什么的回調,你選擇哪個按鈕,我就給你專門的寫一個事件,反正一部動漫,寫死了也就幾十個按鈕事件綁定,而且代碼重用率接近99%,意思就是說:復制一下代碼,然后改一兩個參數就可以了。但是這樣很蠢,所以我希望可以找到更好的辦法。目前來看,還沒找到,如果找到了,后期我會寫在評論中。小程序最近玩的很多了。要換點花樣了。然后,后天就去學校了,真是悲傷。在家的效率很低,但是勝在自由靈活在。在學校,有點怕!
作為半個強迫癥,我怎么著都想著改善UI 所以剛剛發覺那個上一集下一集的按鈕很丑,而且上邊的label部隊稱,所以換了個我比較喜歡的,把樣式文件改了下,好看了不少了:
具體改動了:
<animation.wxss>
.page-body-wrapper {
flex-grow: 1;
}
.index{
background-color: #Eeefaf;
font-family: -apple-system-font,Helvetica Neue,Helvetica,sans-serif;
flex: 1;
min-height: 100%;
font-size: 32rpx;
}
.label
{
width: 750rpx;
position:center;
padding-left: 250rpx
}
<animation.wxml>
<button type="primary" bindtap="Last">上一集</button>
<button type="primary" bindtap="Next">下一集</button>
小程序算是假期的一個調劑吧,不然可能就真的天天看小說,然后逛逛B站了。額,不知道有沒有追看我的文章的body(除了我已知的那位)?很Sorry,明天可能就會很少更新了。后天去縣城,大后天到學校。然后我就要開始我的拼命三郎之路了。如果下學期運氣夠好,計算機三四級一刀斬,成績分數夠我保研,那么以后我估計爆文多的是,如果運氣不夠,那么以后我估計就會坎坷了。在家積蓄了一個月的洪荒之力,已經按耐不住了。去了學校,看命吧!
另外,明天可能開始看看機器學習的內容。有興趣的朋友可以跟上。恩,當然,也許是iOS的開發,還沒準備干嘛但是總是要找點事情干的。講不好發現別的不好玩,又回來折騰小程序了呢!
諸君,拔劍吧!你們要的彈幕君來了。。容我展示下:
更新之后的代碼節選,對照前面的就可以直接找出我修改了哪些地方了!
<animation.js>
function getRandomColor () {
let rgb = []
for (let i = 0 ; i < 3; ++i){
let color = Math.floor(Math.random() * 256).toString(16)
color = color.length == 1 ? '0' + color : color
rgb.push(color)
}
return '#' + rgb.join('')
}
Page({
onReady: function () {
this.videoContext = wx.createVideoContext('myVideo')
this.animation = wx.createAnimation({
transformOrigin: "50% 50%",
duration: 1000,
timingFunction: "ease",
delay: 0
})
<animation.wxml>
<video id="myVideo" class="video" src="http://119.29.74.46/Dj/Dj_{{chapter}}.webm" objectFit="contain" danmu-list="{{danmuList}}" enable-danmu danmu-btn controls></video>
<input bindblur="bindInputBlur" placeholder="來這兒輸入你的彈幕!傾瀉彈藥吧!"/>
<button type="primary" bindtap="bindSendDanmu">發送彈幕</button>
<button type="primary" bindtap="Last">上一集</button>
<button type="primary" bindtap="Next">下一集</button>
知識傳遞力量,技術無國界,文化改變生活!