Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

播放本地文件的时候,好像有些问题 #62

Open
gotosleep7 opened this issue Oct 1, 2020 · 0 comments
Open

播放本地文件的时候,好像有些问题 #62

gotosleep7 opened this issue Oct 1, 2020 · 0 comments

Comments

@gotosleep7
Copy link

我在使用“/storage/emulated/0/Android/data/…………”地址播放文件的时候 尝试了以下三种方式都不行,
AwsomeVideoPlayer("/storage/emulated/0/Android/data/…………")
AwsomeVideoPlayer(file://storage/emulated/0/Android/data/…………)
AwsomeVideoPlayer(File("/storage/emulated/0/Android/data/…………"))

看了一下源代码是是用正则去判断资源类型的
final fileRegx = new RegExp(r'^(file)://([\w.]+/?)\S*');
final isFile = fileRegx.hasMatch(widget.dataSource);
如果isFile是true 则执行
VideoPlayerController.file(widget.dataSource);
但是file点进去入参是需要一个File类型。

是我的使用方法有误吗 ?

我尝试了以下解决方法
添加一个DataSourceType 字段 ,在创建AwsomeVideoPlayer组件的时候,传入资源类型
然后修改了createVideoPlayerController 方法。

  /// 创建video controller
  VideoPlayerController createVideoPlayerController() {
    // final netRegx = new RegExp(r'^(http|https):\/\/([\w.]+\/?)\S*');
    // final fileRegx = new RegExp(r'^(file):\/\/([\w.]+\/?)\S*');
    // final isFile = widget.dataSource is File;
    // final isNetwork = netRegx.hasMatch(widget.dataSource);
    // final isFile = fileRegx.hasMatch(widget.dataSource); 2020-9-30 04:37:23
    // if (isNetwork) {
    //   return VideoPlayerController.network(widget.dataSource);
    // } else if (isFile) {
    //   return VideoPlayerController.file(widget.dataSource);
    // } else {
    //   return VideoPlayerController.asset(widget.dataSource);
    // }
    switch(widget.dataSourceType){
      case AwsomeVideoPlayer.netDataSourceType:
        return VideoPlayerController.network(widget.dataSource);
      case AwsomeVideoPlayer.fileDataSourceType:
        return VideoPlayerController.file(widget.dataSource);
      case AwsomeVideoPlayer.assetDataSourceType:
        return VideoPlayerController.asset(widget.dataSource);
    }

  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant