[add] Implement Bilibili style
This commit is contained in:
@@ -13,10 +13,15 @@ import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.media3.common.MediaItem
|
||||
import androidx.media3.common.Player
|
||||
import androidx.media3.common.Player.STATE_READY
|
||||
import androidx.media3.common.util.UnstableApi
|
||||
import androidx.media3.exoplayer.ExoPlayer
|
||||
import com.acitelight.aether.Global
|
||||
import com.acitelight.aether.model.Video
|
||||
import com.acitelight.aether.model.VideoQueryIndex
|
||||
import com.acitelight.aether.service.MediaManager
|
||||
import com.acitelight.aether.service.RecentManager
|
||||
import com.acitelight.aether.view.hexToString
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -32,25 +37,47 @@ class VideoPlayerViewModel() : ViewModel()
|
||||
var isLongPressing by mutableStateOf(false)
|
||||
var dragging by mutableStateOf(false)
|
||||
|
||||
|
||||
var thumbUp by mutableIntStateOf(0)
|
||||
var thumbDown by mutableIntStateOf(0)
|
||||
var star by mutableStateOf(false)
|
||||
|
||||
private var _init: Boolean = false;
|
||||
var startPlaying by mutableStateOf(false)
|
||||
var renderedFirst = false
|
||||
var video: Video? = null
|
||||
|
||||
@Composable
|
||||
fun Init(videoId: String)
|
||||
{
|
||||
if(_init) return;
|
||||
val context = LocalContext.current
|
||||
_player = remember {
|
||||
ExoPlayer.Builder(context).build().apply {
|
||||
val url = videoId.hexToString()
|
||||
val mediaItem = MediaItem.fromUri(url)
|
||||
setMediaItem(mediaItem)
|
||||
prepare()
|
||||
playWhenReady = true
|
||||
val v = videoId.hexToString()
|
||||
|
||||
remember {
|
||||
viewModelScope.launch {
|
||||
video = MediaManager.queryVideo(v.split("/")[0], v.split("/")[1])
|
||||
RecentManager.Push(context, VideoQueryIndex(v.split("/")[0], v.split("/")[1]))
|
||||
_player = ExoPlayer.Builder(context).build().apply {
|
||||
val url = video?.getVideo() ?: ""
|
||||
val mediaItem = MediaItem.fromUri(url)
|
||||
setMediaItem(mediaItem)
|
||||
prepare()
|
||||
playWhenReady = true
|
||||
|
||||
addListener(object : Player.Listener {
|
||||
override fun onPlaybackStateChanged(playbackState: Int) {
|
||||
if (playbackState == STATE_READY) {
|
||||
startPlaying = true
|
||||
}
|
||||
}
|
||||
|
||||
override fun onRenderedFirstFrame() {
|
||||
super.onRenderedFirstFrame()
|
||||
renderedFirst = true
|
||||
}
|
||||
})
|
||||
}
|
||||
startListen()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user