import 'package:flutter/material.dart'; import 'package:flutter_aliplayer/flutter_aliplayer_factory.dart'; import 'flutter_aliplayer.dart'; export 'flutter_aliplayer.dart'; class FlutterAliListPlayer extends FlutterAliplayer { String playerId = 'listPlayerDefault'; FlutterAliListPlayer.init(String id) : super.init(id); @override /// 创建短视频列表播放 Future create() async { var invokeMethod = FlutterAliPlayerFactory.methodChannel.invokeMethod( 'createAliPlayer', wrapWithPlayerId(arg: PlayerType.PlayerType_List)); sendCustomEvent("source=flutter"); return invokeMethod; } /// 设置预加载的个数 /// 当前位置的前preloadCount和后preloadCount,默认preloadCount = 2 Future setPreloadCount(int count) async { return FlutterAliPlayerFactory.methodChannel .invokeMethod("setPreloadCount", wrapWithPlayerId(arg: count)); } /// 添加vid资源到播放列表中 Future addVidSource({@required vid, @required uid}) async { Map info = {'vid': vid, 'uid': uid}; return FlutterAliPlayerFactory.methodChannel .invokeMethod("addVidSource", wrapWithPlayerId(arg: info)); } /// 添加url资源到播放列表中 Future addUrlSource({@required url, @required uid}) async { Map info = {'url': url, 'uid': uid}; return FlutterAliPlayerFactory.methodChannel .invokeMethod("addUrlSource", wrapWithPlayerId(arg: info)); } /// 从播放列表中删除指定资源 Future removeSource(String uid) async { return FlutterAliPlayerFactory.methodChannel .invokeMethod("removeSource", wrapWithPlayerId(arg: uid)); } /// 获取当前播放资源的uid Future getCurrentUid() { return FlutterAliPlayerFactory.methodChannel .invokeMethod("getCurrentUid", wrapWithPlayerId()); } /// 清除播放列表 Future clear() async { return FlutterAliPlayerFactory.methodChannel .invokeMethod("clear", wrapWithPlayerId()); } /// 设置最大的预缓存的内存大小,默认100M,最小20M Future setMaxPreloadMemorySizeMB(int size) { return FlutterAliPlayerFactory.methodChannel .invokeMethod("setMaxPreloadMemorySizeMB", wrapWithPlayerId(arg: size)); } /// 当前位置移动到下一个进行准备播放 /// 没有入参是url播放方式;有入参是sts播放方式,需要更新sts信息 Future moveToNext( {String? accId, String? accKey, String? token, String? region}) async { Map info = { 'accId': accId, 'accKey': accKey, 'token': token, 'region': region }; return FlutterAliPlayerFactory.methodChannel .invokeMethod("moveToNext", wrapWithPlayerId(arg: info)); } /// 当前位置移动到上一个进行准备播放 /// 没有入参是url播放方式;有入参是sts播放方式,需要更新sts信息 Future moveToPre({ String? accId, String? accKey, String? token, String? region, }) async { Map info = { 'accId': accId, 'accKey': accKey, 'token': token, 'region': region }; return FlutterAliPlayerFactory.methodChannel .invokeMethod("moveToPre", wrapWithPlayerId(arg: info)); } ///移动到指定位置开始准备播放,url播放方式只需要填写uid;sts播放方式,需要更新sts信息 ///uid 指定资源的uid,代表在列表中的唯一标识 Future moveTo( {@required String? uid, String? accId, String? accKey, String? token, String? region}) async { Map info = { 'uid': uid, 'accId': accId, 'accKey': accKey, 'token': token, 'region': region }; return FlutterAliPlayerFactory.methodChannel .invokeMethod("moveTo", wrapWithPlayerId(arg: info)); } }