chudongvip / awesome_video_player

This is a flutter package of video player. it's a very simple and easy to use.
MIT License
196 stars 36 forks source link

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

Open gotosleep7 opened 3 years ago

gotosleep7 commented 3 years ago

我在使用“/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);
    }

  }