titan_plugin 0.0.1 copy "titan_plugin: ^0.0.1" to clipboard
titan_plugin: ^0.0.1 copied to clipboard

outdated

titan sdk flutter plugin

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:titan_plugin/titan_plugin.dart';
import 'package:video_player/video_player.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  TitanPlugin.token = 4;
  TitanPlugin.pauseTimeout = 30000;
  TitanPlugin.sleepTimeout = 60000;
  TitanPlugin.addHttpHeaderBypassKey("key1");
  TitanPlugin.start();
  runApp(MyApp());
}

//class showVideo extends StatefulWidget {
//  @override
//  State<StatefulWidget> createState() {
//    // TODO: implement createState
//    return new _VideoAppState();
//  }
//}
//
//class _VideoAppState extends State<showVideo> {
//  VideoPlayerController _controller;
//
//  @override
//  void initState() {
//    super.initState();
//    TitanPlugin.token = 0;
//    TitanPlugin.pauseTimeout = 30000;
//    TitanPlugin.sleepTimeout = 60000;
//    TitanPlugin.addHttpHeaderBypassKey("key1");
//    TitanPlugin.start();
//    print("aaaaaaa");
//    _controller = VideoPlayerController.network('http://127.0.0.1:29983/vod/user/Ocean_2mbps1.ts?url=aHR0cDovLzQ3LjEwMi4xMDYuMjE2L2Nkbi92aWRlb3MvT2NlYW5fMm1icHMxLnRz&option=e30')
//      ..initialize().then((_) {
//        setState(() {});
//      });
//  }
//
//  @override
//  Widget build(BuildContext context) {
//    return MaterialApp(
//      title: 'Video Demo',
//      home: Scaffold(
//        body: Center(
//          child: _controller.value.initialized
//              ? AspectRatio(
//            aspectRatio: _controller.value.aspectRatio,
//            child: VideoPlayer(_controller),
//          )
//              : Container(),
//        ),
//        floatingActionButton: FloatingActionButton(
//          onPressed: () {
//            setState(() {
//              _controller.value.isPlaying
//                  ? _controller.pause()
//                  : _controller.play();
//            });
//          },
//          child: Icon(
//            _controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
//          ),
//        ),
//      ),
//    );
//  }
//
//  @override
//  void dispose() {
//    super.dispose();
//    _controller.dispose();
//  }
//}
//
//class MyApp extends StatefulWidget {
//  @override
//  _MyAppState createState() => _MyAppState();
//}
//
//class _MyAppState extends State<MyApp> {
//  String _url = 'empty';
//  VideoPlayerController _controller;
//  bool _isPlaying = false;
//  String url = 'http://47.102.106.216/cdn/videos/Ocean_2mbps1.ts';
//  @override
//  void initState() {
//    super.initState();
//    initPlatformState();
//  }
//
//  // Platform messages are asynchronous, so we initialize in an async method.
//  Future<void> initPlatformState() async {
//    TitanPlugin.token = 0;
//    TitanPlugin.pauseTimeout = 30000;
//    TitanPlugin.sleepTimeout = 60000;
//    TitanPlugin.addHttpHeaderBypassKey("key1");
//    TitanPlugin.start();
//
//
//    // If the widget was removed from the tree while the asynchronous platform
//    // message was in flight, we want to discard the reply rather than calling
//    // setState to update our non-existent appearance.
//    if (!mounted) return;
//
//    setState(() {
//    });
//  }
//
//  Future<void> vodPlay(String url) async {
//    String u = await TitanPlugin.getVodUrl(url, "{}");
//    print("url 为 $u");
//    _controller = VideoPlayerController.network(u)
//    // 播放状态
//      ..addListener(() {
//        final bool isPlaying = _controller.value.isPlaying;
//        if (isPlaying != _isPlaying) {
//          setState(() { _isPlaying = isPlaying; });
//        }
//      })
//    // 在初始化完成后必须更新界面
//      ..initialize().then((_) {
//        setState(() {});
//      });
//  }
//
//  Future<void> updateVodUrl(String url) async {
//    String u = await TitanPlugin.getVodUrl(url, "{}");
//    print("url 为 $u");
//    setState(() {
//      _url = u;
//    });
//    vodPlay(u);
//  }
//
//  Future<void> updateDownloadUrl(String url) async {
//    String u = await TitanPlugin.getDownloadUrl(url, "{}");
//    setState(() {
//      _url = u;
//    });
//  }
//
//  Widget player() {
//    if (_controller == null || !_controller.value.initialized) {
//      return new Text("not ready");
//    }
//    return new AspectRatio(
//        aspectRatio: _controller.value.aspectRatio,
//        child: VideoPlayer(_controller));
//  }
//
//  FloatingActionButton button() {
//    if (_controller == null) {
//      return new FloatingActionButton();
//    }
//    return new FloatingActionButton(
//          onPressed: _controller != null && _controller.value.isPlaying
//              ? _controller.pause
//              : _controller.play,
//      child: new Icon(
//        _controller != null && _controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
//      ),
//    );
//  }
//
//  @override
//  Widget build2(BuildContext context) {
//    return MaterialApp(
//      title: 'Video Demo',
//      home: new Scaffold(
//        body: new Center(
//          child: _controller.value.initialized
//          // 加载成功
//              ? new AspectRatio(
//            aspectRatio: _controller.value.aspectRatio,
//            child: VideoPlayer(_controller),
//          ) : new Container(),
//        ),
//        floatingActionButton: new FloatingActionButton(
//          onPressed: _controller.value.isPlaying
//              ? _controller.pause
//              : _controller.play,
//          child: new Icon(
//            _controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
//          ),
//        ),
//      ),
//    );
//  }
//
//  @override
//  Widget build(BuildContext context) {
//    return MaterialApp(
//      home: Scaffold(
//        appBar: AppBar(
//          title: const Text('Qiniu Titan app'),
//        ),
//        body: Center(
//          child: Row(
//            //子组件沿着 Cross 轴(在 Row 中是纵轴)如何摆放,其实就是子组件对齐方式,可选值有:
//            //CrossAxisAlignment.start:子组件在 Row 中顶部对齐
//            //CrossAxisAlignment.end:子组件在 Row 中底部对齐
//            //CrossAxisAlignment.center:子组件在 Row 中居中对齐
//            //CrossAxisAlignment.stretch:拉伸填充满父布局
//            //CrossAxisAlignment.baseline:在 Row 组件中会报错
//              crossAxisAlignment: CrossAxisAlignment.start,
//              //子组件沿着 Main 轴(在 Row 中是横轴)如何摆放,其实就是子组件排列方式,可选值有:
//              //MainAxisAlignment.start:靠左排列
//              //MainAxisAlignment.end:靠右排列
//              //MainAxisAlignment.center:居中排列
//              //MainAxisAlignment.spaceAround:每个子组件左右间隔相等,也就是 margin 相等
//              //MainAxisAlignment.spaceBetween:两端对齐,也就是第一个子组件靠左,最后一个子组件靠右,剩余组件在中间平均分散排列
//              //MainAxisAlignment.spaceEvenly:每个子组件平均分散排列,也就是宽度相等
//              mainAxisAlignment: MainAxisAlignment.center,
//              //Main 轴大小,可选值有:
//              //MainAxisSize.max:相当于 Android 的 match_parent
//              //MainAxisSize.min:相当于 Android 的 wrap_content
//              mainAxisSize: MainAxisSize.max,
//              //不太理解
////            textBaseline: TextBaseline.alphabetic,
//              //子组件排列顺序,可选值有:
//              //TextDirection.ltr:从左往右开始排列
//              //TextDirection.rtl:从右往左开始排列
//              textDirection: TextDirection.ltr,
//              //确定如何在垂直方向摆放子组件,以及如何解释 start 和 end,指定 height 可以看到效果,可选值有:
//              //VerticalDirection.up:Row 从下至上开始摆放子组件,此时我们看到的底部其实是顶部
//              //VerticalDirection.down:Row 从上至下开始摆放子组件,此时我们看到的顶部就是顶部
//              verticalDirection: VerticalDirection.down,
//
//          children:[
//            SizedBox(
//                width: 300.0,
//                height: 80.0,
//                child: new TextField(
//                  onSubmitted: (value){
//                    updateVodUrl(value);
//                    print("------------文字提交触发(键盘按键)--");
//                  },
//                  onEditingComplete: (){
//                    print("----------------编辑完成---");
//                  },
//                  onChanged: (value){
//                    print("----------------输入框中内容为:$value--");
//                  },
//                  keyboardType: TextInputType.text,
//            )
//
//          ),
//            player(),
//          ]
//          )
//        ),
//        floatingActionButton: button(),
//      ),
//    );
//  }
//}

const String VIDEO_URL = 'http://127.0.0.1:29983/vod/user/Ocean_2mbps1.ts?url=aHR0cDovLzQ3LjEwMi4xMDYuMjE2L2Nkbi92aWRlb3MvT2NlYW5fMm1icHMxLnRz&option=e30';

class MyApp extends StatelessWidget {
  const MyApp({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: Text('video_player'),
          ),
          body: HomeContent()),
    );
  }
}

class HomeContent extends StatefulWidget {
  HomeContent({Key key}) : super(key: key);

  _HomeContentState createState() => _HomeContentState();
}

class _HomeContentState extends State<HomeContent> {
  VideoPlayerController _controller;
  Future _initializeVideoPlayerFuture;
  @override
  void initState() {
    super.initState();

    _controller = VideoPlayerController.network(VIDEO_URL);
    _controller.setLooping(true);
    _initializeVideoPlayerFuture = _controller.initialize();
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        FutureBuilder(
          future: _initializeVideoPlayerFuture,
          builder: (context, snapshot) {
            print(snapshot.connectionState);
            if (snapshot.hasError) print(snapshot.error);
            if (snapshot.connectionState == ConnectionState.done) {
              return AspectRatio(
                // aspectRatio: 16 / 9,
                aspectRatio: _controller.value.aspectRatio,
                child: VideoPlayer(_controller),
              );
            } else {
              return Center(
                child: CircularProgressIndicator(),
              );
            }
          },
        ),
        SizedBox(height: 30),
        RaisedButton(
          child: Icon(
            _controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
          ),
          onPressed: () {
            setState(() {
              if (_controller.value.isPlaying) {
                _controller.pause();
              } else {
                // If the video is paused, play it.
                _controller.play();
              }
            });
          },
        )
      ],
    );
  }
}
1
likes
0
pub points
0%
popularity

Publisher

verified publisherqiniu.com

titan sdk flutter plugin

Homepage

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on titan_plugin