提交 308f8ec2 authored 作者: haodaking's avatar haodaking

feat: 视频支持后台播放

上级 43da9a47
...@@ -63,5 +63,6 @@ ...@@ -63,5 +63,6 @@
"version": "1.5.2", "version": "1.5.2",
"provider": "wxa75efa648b60994b" "provider": "wxa75efa648b60994b"
} }
} },
"requiredBackgroundModes": ["audio"]
} }
...@@ -5,7 +5,7 @@ Component({ ...@@ -5,7 +5,7 @@ Component({
* 组件的属性列表 * 组件的属性列表
*/ */
properties: { properties: {
hasBackgroundAudio: { type: Boolean, defaut: false } hasBackgroundAudio: { type: Boolean, value: false }
}, },
/** /**
......
...@@ -269,6 +269,14 @@ module.exports = Behavior({ ...@@ -269,6 +269,14 @@ module.exports = Behavior({
let isAutoNext = !this.data.isAutoNext let isAutoNext = !this.data.isAutoNext
this.setData({ isAutoNext }) this.setData({ isAutoNext })
wx.setStorageSync('isAutoNext', isAutoNext) wx.setStorageSync('isAutoNext', isAutoNext)
},
// 进入后台音频播放模式
onRequestBackgroundPlayback() {
this.player.requestBackgroundPlayback()
},
// 退出后台音频播放模式
onExitBackgroundPlayback() {
this.player.exitBackgroundPlayback()
} }
} }
}) })
...@@ -6,7 +6,7 @@ Component({ ...@@ -6,7 +6,7 @@ Component({
*/ */
properties: { properties: {
ppts: { type: Array, value: [] }, ppts: { type: Array, value: [] },
hasBackgroundAudio: { type: Boolean, defaut: false } hasBackgroundAudio: { type: Boolean, value: true }
}, },
/** /**
...@@ -24,6 +24,7 @@ Component({ ...@@ -24,6 +24,7 @@ Component({
this.pause() this.pause()
this.data.isFullscreen && this.exitFullScreen() this.data.isFullscreen && this.exitFullScreen()
this.triggerEvent('switchAudio') this.triggerEvent('switchAudio')
} },
noop() {}
} }
}) })
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
bindloadedmetadata="onLoadedMetaData" bindloadedmetadata="onLoadedMetaData"
bindfullscreenchange="onFullScreenChange" bindfullscreenchange="onFullScreenChange"
binderror="onError" binderror="onError"
bindtap="toggleControls"
> >
<!-- 中间播放按钮 --> <!-- 中间播放按钮 -->
<block wx:if="{{ showCenterPlay }}"> <block wx:if="{{ showCenterPlay }}">
...@@ -29,13 +30,13 @@ ...@@ -29,13 +30,13 @@
</view> </view>
</block> </block>
<block wx:else> <block wx:else>
<view class="cover" bindtap="toggleControls"></view> <!-- <view class="cover" bindtap="toggleControls"></view> -->
<view class="tips" wx:if="{{ status === 'waiting' }}"> <view class="tips" wx:if="{{ status === 'waiting' }}">
<!-- 缓冲中 --> <!-- 缓冲中 -->
<view class="loading"></view> <view class="loading"></view>
</view> </view>
<block wx:if="{{ showControls }}"> <block wx:if="{{ showControls }}">
<view class="toolbar"> <view class="toolbar" catchtap="noop">
<view class="toolbar-inner"> <view class="toolbar-inner">
<!-- 返回 --> <!-- 返回 -->
<image <image
...@@ -44,12 +45,11 @@ ...@@ -44,12 +45,11 @@
bindtap="back" bindtap="back"
hidden="{{ !isFullscreen }}" hidden="{{ !isFullscreen }}"
></image> ></image>
<!-- 切换音频 --> <!-- 切换背景音频 -->
<image <image
src="/assets/images/player_audio.png" src="/assets/images/player_audio.png"
class="toolbar-button toolbar-button__audio" class="toolbar-button toolbar-button__audio"
bindtap="switchAudio" bindtap="onRequestBackgroundPlayback"
hidden="{{ !hasBackgroundAudio }}"
></image> ></image>
<!-- 设置 --> <!-- 设置 -->
<image <image
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
></image> ></image>
</view> </view>
</view> </view>
<view class="controls" wx:if="{{ controls }}"> <view class="controls" wx:if="{{ controls }}" catchtap="noop">
<view class="controls-inner"> <view class="controls-inner">
<!-- 播放 --> <!-- 播放 -->
<image <image
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
autoplay="{{ autoplay }}" autoplay="{{ autoplay }}"
startTime="{{ progress.cpt }}" startTime="{{ progress.cpt }}"
bindtimeupdate="onTimeupdate" bindtimeupdate="onTimeupdate"
bindswitchAudio="onSwitchVideo"
bindended="onEnded" bindended="onEnded"
wx:if="{{ hasVideo }}" wx:if="{{ hasVideo }}"
></player-video> ></player-video>
...@@ -14,7 +13,6 @@ ...@@ -14,7 +13,6 @@
id="player" id="player"
src="{{ video.SQ }}" src="{{ video.SQ }}"
bindtimeupdate="onTimeupdate" bindtimeupdate="onTimeupdate"
bindswitchAudio="onSwitchVideo"
wx:elif="{{ hasAudio }}" wx:elif="{{ hasAudio }}"
></player-audio> ></player-audio>
</view> </view>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论