flutter_aliplayer 5.4.0 copy "flutter_aliplayer: ^5.4.0" to clipboard
flutter_aliplayer: ^5.4.0 copied to clipboard

outdated

Aliyun Player With Flutter

flutter_aliplayer #

A new flutter plugin project , The project supports Android and iOS base on AliyunPlayerSDK Android SDK URL iOS SDK URL

Installation #

dependencies:
  flutter_aliplayer: ^{{latest version}}

Example #

import 'package:flutter_aliplayer/flutter_aliplayer.dart';
import 'package:flutter_aliplayer/flutter_aliplayer_factory.dart';


class PlayerPage extends StatefulWidget {
  final ModeType playMode;
  final Map<String, dynamic> dataSourceMap;

  PlayerPage({Key key, this.playMode, this.dataSourceMap})
      : assert(playMode != null),
        super(key: key);

  @override
  _PlayerPageState createState() => _PlayerPageState();
}

class _PlayerPageState extends State<PlayerPage> with WidgetsBindingObserver {
  FlutterAliplayer fAliplayer;
  ModeType _playMode;
  Map<String, dynamic> _dataSourceMap;

  @override
  void initState() {
    super.initState();
    //创建播放器
    fAliplayer = FlutterAliPlayerFactory.createAliPlayer();
    _initListener();
  }

    ///设置监听
  _initListener() {
    fAliplayer.setOnPrepard((playerId) {});
    fAliplayer.setOnRenderingStart((playerId) {});
    fAliplayer.setOnVideoSizeChanged((width, height,playerId) {});
    fAliplayer.setOnStateChanged((newState,playerId) {});
    fAliplayer.setOnLoadingStatusListener(
        loadingBegin: (playerId) {},
        loadingProgress: (percent, netSpeed,playerId) {},
        loadingEnd: (playerId) {});
    fAliplayer.setOnSeekComplete((playerId) {});
    fAliplayer.setOnInfo((infoCode, extraValue, extraMsg,playerId) {});
    fAliplayer.setOnCompletion((playerId) {});
    fAliplayer.setOnTrackReady((playerId) {});
    fAliplayer.setOnSnapShot((path,playerId) {});
    fAliplayer.setOnError((errorCode, errorExtra, errorMsg,playerId) {});
    fAliplayer.setOnTrackChanged((value,playerId) {});
    fAliplayer.setOnThumbnailPreparedListener(
        preparedSuccess: (playerId) {}, preparedFail: (playerId) {});
  }

  @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:
    }
  }
}
18
likes
0
pub points
83%
popularity

Publisher

unverified uploader

Aliyun Player With Flutter

Homepage

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_aliplayer