# flutter_aliplayer **Repository Path**: ichaly/flutter_aliplayer ## Basic Information - **Project Name**: flutter_aliplayer - **Description**: flutter_aliplayer - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-04-25 - **Last Updated**: 2021-04-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # flutter_aliplayer A new flutter plugin project , The project supports Android and iOS base on AliyunPlayerSDK [Android SDK URL](https://help.aliyun.com/document_detail/94328.html?spm=a2c4g.11186623.6.979.1d5c67b4gEmBvH) [iOS SDK URL](https://help.aliyun.com/document_detail/94428.html?spm=a2c4g.11186623.6.980.7fc22a88xOI4gc) ## Installation ```yaml dependencies: flutter_aliplayer: ^{{latest version}} ``` ## Example ```dart import 'package:flutter_aliplayer/flutter_aliplayer.dart'; import 'package:flutter_aliplayer/flutter_aliplayer_factory.dart'; class PlayerPage extends StatefulWidget { final ModeType playMode; final Map dataSourceMap; PlayerPage({Key key, this.playMode, this.dataSourceMap}) : assert(playMode != null), super(key: key); @override _PlayerPageState createState() => _PlayerPageState(); } class _PlayerPageState extends State with WidgetsBindingObserver { FlutterAliplayer fAliplayer; ModeType _playMode; Map _dataSourceMap; @override void initState() { super.initState(); //创建播放器 fAliplayer = FlutterAliPlayerFactory().createAliPlayer(); _initListener(); } ///设置监听 _initListener() { fAliplayer.setOnPrepard(() {}); fAliplayer.setOnRenderingStart(() {}); fAliplayer.setOnVideoSizeChanged((width, height) {}); fAliplayer.setOnStateChanged((newState) {}); fAliplayer.setOnLoadingStatusListener( loadingBegin: () {}, loadingProgress: (percent, netSpeed) {}, loadingEnd: () {}); fAliplayer.setOnSeekComplete(() {}); fAliplayer.setOnInfo((infoCode, extraValue, extraMsg) {}); fAliplayer.setOnCompletion(() {}); fAliplayer.setOnTrackReady(() {}); fAliplayer.setOnSnapShot((path) {}); fAliplayer.setOnError((errorCode, errorExtra, errorMsg) {}); fAliplayer.setOnTrackChanged((value) {}); fAliplayer.setOnThumbnailPreparedListener( preparedSuccess: () {}, preparedFail: () {}); } @override void dispose() { fAliplayer.stop(); fAliplayer.destroy(); super.dispose(); } @override Widget build(BuildContext context) { var x = 0.0; var y = 0.0; Orientation orientation = MediaQuery.of(context).orientation; var width = MediaQuery.of(context).size.width; var height; if (orientation == Orientation.portrait) { height = width * 9.0 / 16.0; } else { height = MediaQuery.of(context).size.height; } AliPlayerView aliPlayerView = AliPlayerView( onCreated: onViewPlayerCreated, x: x, y: y, width: width, height: height); return OrientationBuilder( builder: (BuildContext context, Orientation orientation) { return Scaffold( body: Column( children: [ Container( color: Colors.black, child: aliPlayerView, width: width, height: height), ], ), ); }, ); } ///设置播放源 void onViewPlayerCreated() async { switch (_playMode) { case ModeType.URL: this.fAliplayer.setUrl(_dataSourceMap[DataSourceRelated.URL_KEY]); break; case ModeType.STS: this.fAliplayer.setVidSts( vid: _dataSourceMap[DataSourceRelated.VID_KEY], region: _dataSourceMap[DataSourceRelated.REGION_KEY], accessKeyId: _dataSourceMap[DataSourceRelated.ACCESSKEYID_KEY], accessKeySecret: _dataSourceMap[DataSourceRelated.ACCESSKEYSECRET_KEY], securityToken: _dataSourceMap[DataSourceRelated.SECURITYTOKEN_KEY], definitionList: _dataSourceMap[DataSourceRelated.DEFINITION_LIST], previewTime: _dataSourceMap[DataSourceRelated.PREVIEWTIME_KEY]); break; case ModeType.AUTH: this.fAliplayer.setVidAuth( vid: _dataSourceMap[DataSourceRelated.VID_KEY], region: _dataSourceMap[DataSourceRelated.REGION_KEY], playAuth: _dataSourceMap[DataSourceRelated.PLAYAUTH_KEY], definitionList: _dataSourceMap[DataSourceRelated.DEFINITION_LIST], previewTime: _dataSourceMap[DataSourceRelated.PREVIEWTIME_KEY]); break; default: } } } ```