flutter_tencentplayer 0.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 68

线上项目应用运行效果: http://file.jinxianyun.com/tencentplayer.MP4

1.Setup #

```
flutter_tencentplayer: ${last_version}

or

flutter_tencentplayer:
    git:
      url: https://github.com/qq326646683/flutter_tencentplayer.git
```

For Android

  1. project/android/build.gradle 添加依赖的aar:
def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {
    pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
}

allprojects {
    repositories {
        google()
        jcenter()
        flatDir {
            dirs "${plugins.get("flutter_tencentplayer")}android/libs"
        }
    }
}
  1. AndroidManifest.xml 声明权限:

     <!--网络权限-->
    
     <uses-permission android:name="android.permission.INTERNET" />
    
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    
     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    
     <!--点播播放器悬浮窗权限-->
    
     <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    
     <!--存储-->
    
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    

For Ios


//项目的info.plist文件上添加如下权限 
<key>NSAppTransportSecurity</key>
	<dict>
		<key>NSAllowsArbitraryLoads</key>
		<true/>
  </dict>

2.Usage(TencentPlayer) #

flutter_tencentplayer 提供video_player 相似api

支持功能 #

  1. 支持直播源
  2. 视频跳转
  3. 切换视频源
  4. 边下边播放
  5. 清晰度切换
  6. 设置播放速度

1.初始化播放器 #

提供 asset、network、filePath、fileId四种方式播放

TencentPlayerController _controller;

_MyAppState() {
    listener = () {
      if (!mounted) {
        return;
      }
      setState(() {});
    };
}

initState() {
    _controller = TencentPlayerController.network('http://file.jinxianyun.com/testhaha.mp4', playerConfig: PlayerConfig())
    //_controller = TencentPlayerController.asset('static/tencent1.mp4')
    //_controller = TencentPlayerController.file('/storage/emulated/0/test.mp4')
    //_controller = TencentPlayerController.network(null, playerConfig: {auth: {"appId": 1252463788, "fileId": '4564972819220421305'}})
    ..initialize().then((_) {
        setState(() {});
      });
    _controller.addListener(listener);
}

2. (播放器配置参数 ) #

_controller = TencentPlayerController.network(url, playerConfig: PlayerConfig())

PropTypeDefaultNote
autoPlaybooltrue是否自动播放
loopboolfalse是否循环播放
headersMap<String, String>请求头
cachePathString缓存路径(边播放边下载)
progressIntervalint200播放进度回调频率(毫秒)
startTimeint0哪里开始播放(秒)
authMap<String, dynamic>云点播视频源appId&fileId

3. (播放器回调) #

Text("总时长:" + _controller.value.duration.toString())
PropTypeNote
initializedbool是否初始化完成从而显示播放器
aspectRatiodouble用来控制播放器宽高比
durationDuration时长
positionDuration播放进度
playableDuration缓冲进度
isPlayingbool是否在播放
sizeSize视频宽高
isLoadingbool是否在加载
netSpeedint视频播放网速
ratedouble播放速度
bitrateIndexint视频清晰度

4. (播放器事件) #

a.跳转进度

_controller.seekTo(Duration(seconds: 5));

b.设置播放速度

_controller.setRate(1.5); // 1.0 ~ 2.0

c.切换播放源

controller?.removeListener(listener);
controller?.pause();
controller = TencentPlayerController.network(url, playerConfig: PlayerConfig(startTime: startTime ?? controller.value.position.inSeconds));
controller?.initialize().then((_) {
  if (mounted) setState(() {});
});
controller?.addListener(listener);

d.切换清晰度(实质就是切换播放源)

3.Usage(Download) #

离线下载, 支持断点续传(这里只支持m3u8视频、fileId), 支持多文件同时下载

1.初始化下载器 #

DownloadController _downloadController;

_MyAppState() {
    downloadListener = () {
      if (!mounted) {
        return;
      }
      setState(() {});
    };
}

initState() {
    _downloadController = DownloadController('/storage/emulated/0/tencentdownload', appId: 1252463788);
    _downloadController.addListener(downloadListener);
}

2. (下载事件) #

a. 下载

_downloadController.dowload("4564972819220421305", quanlity: 2);
// _downloadController.dowload("http://1253131631.vod2.myqcloud.com/26f327f9vodgzp1253131631/f4bdff799031868222924043041/playlist.m3u8");

b. 暂停下载

_downloadController.pauseDownload("4564972819220421305");
// _downloadController.stopDownload("http://1253131631.vod2.myqcloud.com/26f327f9vodgzp1253131631/f4bdff799031868222924043041/playlist.m3u8");

b. 取消下载

_downloadController.cancelDownload("4564972819220421305");
// _downloadController.cancelDownload("http://1253131631.vod2.myqcloud.com/26f327f9vodgzp1253131631/f4bdff799031868222924043041/playlist.m3u8");

3. (下载信息回调) #

因为支持多文件同时下载,回调以Map<String, DownloadValue>返回,key为url/fileId

PropTypeNote
downloadStatusString"start"、"progress"、"stop"、"complete"、"error"
quanlityint1: "FLU"、2: "SD"、3: "HD"、4: "FHD"、5: "2K"、6: "4K"
durationint
sizeint文件大小
downloadSizeint已下载大小
progressint已下载大小
playPathString下载文件的绝对路径
isStopbool是否暂停下载
urlString下载的视频链接
fileIdString下载的视频FileId
errorString下载的错误信息

4.Example

0.0.2 #

关闭android播放时默认缓存

0.0.3 #

  1. 解决IOS切换视频黑屏
  2. 解决IOS设置loop属性无效问题
  3. 修复autoPlay为false的bug
  4. 升级IOS/Android LiteAVSDK 6.8.7969
  5. 修复退出播放页面还有声音

example/README.md

flutter_tencentplayer_example #

Demonstrates how to use the flutter_tencentplayer plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_tencentplayer: ^0.0.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_tencentplayer/flutter_tencentplayer.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
51
Health:
Code health derived from static analysis. [more]
97
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
68
Learn more about scoring.

We analyzed this package on Jan 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health issues and suggestions

Document public APIs. (-0.03 points)

87 out of 90 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/view/tencent_player.dart. (-1.49 points)

Analysis of lib/view/tencent_player.dart reported 3 hints:

line 25 col 50: The member 'textureId' can only be used within 'package:flutter_tencentplayer/controller/tencent_player_controller.dart' or a test.

line 37 col 36: The member 'textureId' can only be used within 'package:flutter_tencentplayer/controller/tencent_player_controller.dart' or a test.

line 48 col 36: The member 'textureId' can only be used within 'package:flutter_tencentplayer/controller/tencent_player_controller.dart' or a test.

Fix lib/controller/download_controller.dart. (-1 points)

Analysis of lib/controller/download_controller.dart reported 2 hints:

line 10 col 31: The value of the field '_eventSubscription' isn't used.

line 10 col 31: Cancel instances of dart.async.StreamSubscription.

Fix lib/model/download_value.dart. (-0.50 points)

Analysis of lib/model/download_value.dart reported 1 hint:

line 1 col 8: Unused import: 'dart:io'.

Fix additional 4 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/controller/tencent_player_controller.dart (Run flutter format to format lib/controller/tencent_player_controller.dart.)
  • lib/flutter_tencentplayer.dart (Run flutter format to format lib/flutter_tencentplayer.dart.)
  • lib/model/player_config.dart (Run flutter format to format lib/model/player_config.dart.)
  • lib/model/tentcent_player_value.dart (Run flutter format to format lib/model/tentcent_player_value.dart.)

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test