GithubHelp home page GithubHelp logo

zhzc0x / videoplayer-compose Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 1.0 43.15 MB

Compose桌面端视频播放器,基于JavaFx组件MediaPlayer开发,独立运行,不依赖任何其它视频播放器

Kotlin 100.00%
compose deskop javafx videoplayer

videoplayer-compose's Introduction

Compose desktop video player

基于JavaFx组件MediaPlayer开发,独立运行,不依赖任何其它视频播放器

代码示例

var seek by remember { mutableStateOf(0f) }                                                           
var progress by remember { mutableStateOf(Progress.ZERO) }                                            
var showLoading by remember{ mutableStateOf(false) }                                                  
var showErrorHint by remember{ mutableStateOf(false) }                                                
var videoModifier by remember { mutableStateOf(Modifier.size(DpSize.Zero)) }                          
Box(Modifier.fillMaxWidth().weight(1f).background(Color.Black), contentAlignment= Alignment.Center) {  
    progress = VideoPlayer(videoModifier, videoUrl, mediaState, volume, seek).value                   
    if(showLoading){                                                                                  
        CircularProgressIndicator(Modifier.size(80.dp), Color.White, strokeWidth = 6.dp)              
    }                                                                                                 
    if(showErrorHint){                                                                                
        Column(Modifier.clickable {                                                                   
            MainScope().launch {                                                                       
                videoUrl = ""                                                                         
                delay(500)                                                                            
                videoUrl = VIDEO_URL_LIST[videoUrlIndex]                                              
            }                                                                                         
        }, horizontalAlignment = Alignment.CenterHorizontally) {                                       
            Icon(Icons.Default.Refresh, "", Modifier.size(60.dp), tint = Color.White)                 
            Spacer(Modifier.height(16.dp))                                                            
            Text("加载失败", color=Color.White, fontSize = 18.sp)                                         
        }                                                                                             
    }                                                                                                 
}                                                                                                     
......
LaunchedEffect(mediaState.value){                            
    println("out mediaState=${mediaState.value}")           
    when (mediaState.value) {                               
        MediaState.LOADING -> {                             
            showLoading = true                              
            showErrorHint = false                           
            //由于覆盖在JavaFx组件上面的UI无法显示出来,所以先将其尺寸设置为0,等加载完成后恢复 
            videoModifier = Modifier.size(DpSize.Zero)      
        }                                                   
        MediaState.READY -> {                               
            delay(1000)                                     
            showLoading = false                             
            videoModifier = Modifier.fillMaxSize()          
        }                                                   
        MediaState.ERROR -> {                               
            showErrorHint = true                            
            showLoading = false                             
            videoModifier = Modifier.size(DpSize.Zero)      
        }                                                   
        else -> {}                                          
    }                                                       
}                                                           

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.