昨天没事又扫了一下,发现NeteaseCloudMusicApi有更新接口,还是视频的
精选视频添加起来还是很不错的,惊喜一,因为都是使用Kotlin
已经不再使用Rxjava2
了,在寻找定时触发替代品时发现了ticker
,惊喜二,有钱就是了不起,播放在线不卡。。。我自己搭过阿里视频服务器4M宽带,播放时卡成狗
预览
9-7c399480-dc43-11eb-9085-629d78835e8f.gif)
实现设计
框架
精选视频的的实现是通过ViewPager2
+SimpleExoPlayer
实现的
将ViewPager2
修改为纵向滑动
1 | <androidx.viewpager2.widget.ViewPager2 |
播放视频
1 | private fun prepareVideoPlayer() { |
Slider
进度条更新采用ticker
实现,很不错的方式,个人比较喜欢
初始化
1
2
3
4
5
6
7
private val tickerChannel = ticker(delayMillis = 300, initialDelayMillis = 0)
// @ObsoleteCoroutinesApi
// private fun tickCancel() {
// tickerChannel.cancel()
// }调用
1
2
3
4
5
6
7
8
9
10lifecycleScope.launch {
for (event in tickerChannel) {
if (simplePlayer.playWhenReady) {
val position = simplePlayer.currentPosition * 1f
if (progress.valueTo > position)
progress.value = position
}
}
}
参考
https://stackoverflow.com/questions/54827455/how-to-implement-timer-with-kotlin-coroutines/54828055
https://codelabs.developers.google.com/codelabs/exoplayer-intro