ve_vod 1.42.3-3 copy "ve_vod: ^1.42.3-3" to clipboard
ve_vod: ^1.42.3-3 copied to clipboard

This Flutter plugin provides vod player sdk native APIs for you to implement video play functions in your application

example/lib/main.dart

import 'dart:io';
import 'dart:ui';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:ve_vod/ve_vod.dart';
import 'package:vod_player_flutter_example/global_configuration.dart';
import 'package:vod_player_flutter_example/platform_keys.dart';
import 'package:vod_player_flutter_example/short_video_play_scene.dart';
import 'package:vod_player_flutter_example/video_preload.dart';
import 'package:shared_preferences/shared_preferences.dart';

void main() {
  runApp(const MyApp());
  DartPluginRegistrant.ensureInitialized();
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  SharedPreferences? _sp;

  @override
  void initState() {
    super.initState();
    SharedPreferences.getInstance().then((value) {
      setState(() {
        _sp = value;
      });
    });
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    // open log module
    await FlutterTTSDKManager.openAllLog();

    // regist log callback
    TTFLogger.onLog = (logLevel, msg) {
      print(msg);
    };

    if (Platform.isAndroid) {
      FlutterTTSDKManager.setStaticOption(90, 4);
      FlutterTTSDKManager.setStaticOption(12003, "test");
      FlutterTTSDKManager.setStaticOption(738, 2.2);
      FlutterTTSDKManager.setStaticOption(TTMediaDataLoaderKey.keyIsEnableMDL2,
          (_sp?.getBool(GlobalConfigurationKey.mdlV2EnabledKey) ?? false) ? 1 : 0);
    } else if (Platform.isIOS) {
      FlutterTTSDKManager.setStaticOption(
          TTMediaDataLoaderKey.keyIsEnableMDL2, _sp?.getBool(GlobalConfigurationKey.mdlV2EnabledKey));
    }

    // final licPath = await rootBundle.load("assets/VEVod.license");
    // final directory = await getApplicationDocumentsDirectory();
    // String licPath = '${directory.path}/VEVod.license';
    String licPath = 'assets/VEVod.license';
    String channel = Platform.isAndroid ? 'xiaomi' : 'App Store';
    TTSDKVodConfiguration vodConfig = TTSDKVodConfiguration();
    vodConfig.cacheMaxSize = 300 * 1024 * 1024;
    TTSDKConfiguration sdkConfig = TTSDKConfiguration.defaultConfigurationWithAppIDAndLicPath(
        appID: '229234', licenseFilePath: licPath, channel: channel);
    sdkConfig.vodConfiguration = vodConfig;
    sdkConfig.channel = "ByteVodDemoAndroid";
    sdkConfig.appName = "bytevod_flutter_demo";
    sdkConfig.appVersion = "1.1.1";
    FlutterTTSDKManager.startWithConfiguration(sdkConfig);
    // deviceID
    FlutterTTSDKManager.setCurrentUserUniqueID('test_1234');
    String? uniqueID = await FlutterTTSDKManager.getCurrentUserUniqueID();
    String? deviceID = await FlutterTTSDKManager.getDeviceID();
    String? engineUniqueId = await FlutterTTSDKManager.getEngineUniqueId();
    print("TTF -- uniqueId:$uniqueID deviceId:$deviceID engineUniqueId:$engineUniqueId");
    _enableEngineStrategy(false);

    if (!mounted) return;
    setState(() {});
  }

  void _enableEngineStrategy(bool enable) {
    if (enable) {
      TTVideoEngineStrategy.init();
      TTVideoEngineStrategy.onCreatePreRenderEngine = ((source) async {
        VodPlayerFlutter player = VodPlayerFlutter();
        String coreHashHex = await player.createPlayer(vid: source.getVid, preCreated: true);
        player.setUrlSource(source as TTVideoEngineUrlSource);
        player.setHLSMultiBitrateConfig(
          selectHlsVideoStream: () {
            return 800 * 1024;
          },
          selectHlsRendition: (variantIndex) {
            return 0;
          },
        );
        player.setHardwareDecode(GlobalConfiguration.isHardwareDecode);
        player.setTrackVolumeEnabled(GlobalConfiguration.isTrackVolume);
        player.setScalingMode(TTVideoEngineScalingMode.TTVideoEngineScalingModeAspectFit);
        player.openTextureRender(!GlobalConfiguration.closeTextureRender);
        player.setLooping(true);
        player.setCustomHeader('x-tt-flutter-test-demo', '1');
        print(
            'TTVideoEngineStrategy onCreatePreRenderEngine, hashCode:${player.hashCode} engine:$coreHashHex vid:${source.getVid}');
        return player;
      });
      TTVideoEngineStrategy.enableEngineStrategy(
          strategyType: TTVideoEngineStrategyType.preloadAndPreRender, scene: TTVideoEngineStrategyScene.smallVideo);
      print('TTF -- TTVideoEngineStrategy - init end');
    } else {
      TTVideoEngineStrategy.clearAllEngineStrategy();
      print('TTF -- TTVideoEngineStrategy - clear');
    }
  }

  final List<String> _resolutionItems = ['480P', '540P', '720P', '1080P', 'HDR', 'HDR 720P', 'HDR 1080P'];
  String _defaultResolution = '720P';

  final List<String> _scaleModeItems = ['None', 'AspectFit', 'AspectFill', 'Fill'];
  String _defaultScale = 'None';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Builder(
        builder: (context) => Scaffold(
          appBar: AppBar(
            title: const Text('Plugin example app'),
          ),
          body: Center(
            child: Container(
                child: SingleChildScrollView(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  Padding(
                      padding: const EdgeInsets.all(16.0),
                      child: TextField(
                        controller: TextEditingController(
                          text: ShortVideoScene.sTestUrl,
                        ),
                        onSubmitted: _didInputUrl,
                        onChanged: _didInputUrl,
                        decoration: const InputDecoration(
                          labelText: 'input test URL',
                        ),
                        keyboardType: TextInputType.url,
                        textInputAction: TextInputAction.done,
                      )),
                  Padding(
                      padding: const EdgeInsets.all(16.0),
                      child: TextField(
                        controller: TextEditingController(
                          text: ShortVideoScene.sTestSubtitlesJson,
                        ),
                        onSubmitted: (json) {
                          ShortVideoScene.sTestSubtitlesJson = json;
                        },
                        onChanged: (json) {
                          ShortVideoScene.sTestSubtitlesJson = json;
                        },
                        decoration: const InputDecoration(
                          labelText: 'input test subtitle directUrl jSON',
                        ),
                        keyboardType: TextInputType.url,
                        textInputAction: TextInputAction.done,
                      )),
                  Padding(
                      padding: const EdgeInsets.all(16.0),
                      child: TextField(
                        controller: TextEditingController(
                          text: ShortVideoScene.sTestVid,
                        ),
                        onSubmitted: _didInputVid,
                        onChanged: _didInputVid,
                        decoration: const InputDecoration(
                          labelText: 'input test vid',
                        ),
                        keyboardType: TextInputType.url,
                        textInputAction: TextInputAction.done,
                      )),
                  Padding(
                      padding: const EdgeInsets.all(16.0),
                      child: TextField(
                        controller: TextEditingController(
                          text: ShortVideoScene.sTestToken,
                        ),
                        onSubmitted: _didInputToken,
                        onChanged: _didInputToken,
                        decoration: const InputDecoration(
                          labelText: 'input test playAuthToken',
                        ),
                        keyboardType: TextInputType.url,
                        textInputAction: TextInputAction.done,
                      )),
                  Padding(
                      padding: const EdgeInsets.all(16.0),
                      child: TextField(
                        controller: TextEditingController(
                          text: ShortVideoScene.sTestSubtitleToken,
                        ),
                        onSubmitted: _didInputSubtitleToken,
                        onChanged: _didInputSubtitleToken,
                        decoration: const InputDecoration(
                          labelText: 'input test subtitleAuthToken',
                        ),
                        keyboardType: TextInputType.url,
                        textInputAction: TextInputAction.done,
                      )),
                  Container(
                    padding: const EdgeInsets.all(8.0),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        ElevatedButton(
                            onPressed: () {
                              if (GlobalConfiguration.testVidSource) {
                                String vid = ShortVideoScene.sTestVid;
                                String token = ShortVideoScene.sTestToken;
                                assert(vid.isNotEmpty && token.isNotEmpty, 'need valid test url');
                              } else {
                                String url = ShortVideoScene.sTestUrl;
                                assert(url.isNotEmpty, 'need valid test url');
                              }

                              Navigator.of(context).push(
                                MaterialPageRoute(
                                  builder: (context) => const ShortVideoScene(),
                                ),
                              );
                            },
                            child: const Text("small video")),
                        ElevatedButton(
                            onPressed: () {
                              Navigator.of(context).push(
                                MaterialPageRoute(
                                  builder: (context) => const VideoPreload(),
                                ),
                              );
                            },
                            child: const Text("preload")),
                        ElevatedButton(
                            onPressed: () {
                              setState(() {
                                ShortVideoScene.sTestUrl = "";
                                ShortVideoScene.sTestVid = "";
                                ShortVideoScene.sTestToken = "";
                              });
                            },
                            child: const Text("clear input")),
                      ],
                    ),
                  ),
                  Container(
                    padding: const EdgeInsets.all(16.0),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        const Text('isClip'),
                        Switch(
                            value: GlobalConfiguration.isClip,
                            onChanged: (value) {
                              setState(() {
                                GlobalConfiguration.isClip = value;
                              });
                            })
                      ],
                    ),
                  ),
                    Container(
                    padding: const EdgeInsets.all(16.0),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        const Text('scaleMode'),
                        DropdownButton<String>(
                          value: _defaultScale,
                          onChanged: (String? newValue) {
                            setState(() {
                              GlobalConfiguration.scaleMode = newValue!;
                              _defaultScale = newValue;
                              print(
                                  "TTF -- set scaleMode $newValue");
                            });
                          },
                          items: _scaleModeItems.map<DropdownMenuItem<String>>((String value) {
                            return DropdownMenuItem<String>(
                              value: value,
                              child: Text(value),
                            );
                          }).toList(),
                        ),
                      ],
                    ),
                  ),
                  Container(
                    padding: const EdgeInsets.all(16.0),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        const Text('test vid'),
                        Switch(
                            value: GlobalConfiguration.testVidSource,
                            onChanged: (value) {
                              setState(() {
                                GlobalConfiguration.testVidSource = value;
                              });
                            })
                      ],
                    ),
                  ),
                  Container(
                    padding: const EdgeInsets.all(16.0),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        const Text('vid quality on start'),
                        DropdownButton<String>(
                          value: _defaultResolution,
                          onChanged: (String? newValue) {
                            setState(() {
                              GlobalConfiguration.vidResoluytionBFS = newValue!;
                              _defaultResolution = newValue;
                              print(
                                  "TTF -- set vid quality on start $newValue type=${ShortVideoScene.trasnResolutionString(newValue).toString()}");
                            });
                          },
                          items: _resolutionItems.map<DropdownMenuItem<String>>((String value) {
                            return DropdownMenuItem<String>(
                              value: value,
                              child: Text(value),
                            );
                          }).toList(),
                        ),
                      ],
                    ),
                  ),
                  Container(
                    padding: const EdgeInsets.all(16.0),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        const Text('iOS enable HDR'),
                        Switch(
                            value: GlobalConfiguration.isHDRSource,
                            onChanged: (value) {
                              setState(() {
                                GlobalConfiguration.isHDRSource = value;
                              });
                            })
                      ],
                    ),
                  ),
                  Container(
                    padding: const EdgeInsets.all(16.0),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        const Text('HW decoder'),
                        Switch(
                            value: GlobalConfiguration.isHardwareDecode,
                            onChanged: (value) {
                              setState(() {
                                GlobalConfiguration.isHardwareDecode = value;
                              });
                            })
                      ],
                    ),
                  ),
                  Container(
                    padding: const EdgeInsets.all(16.0),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        const Text('TrackVolume'),
                        Switch(
                            value: GlobalConfiguration.isTrackVolume,
                            onChanged: (value) {
                              setState(() {
                                GlobalConfiguration.isTrackVolume = value;
                              });
                            })
                      ],
                    ),
                  ),
                  Container(
                    padding: const EdgeInsets.all(16.0),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        const Text('SurfaceView(for Android)'),
                        Switch(
                            value: GlobalConfiguration.useSurfaceView,
                            onChanged: (value) {
                              setState(() {
                                GlobalConfiguration.useSurfaceView = !GlobalConfiguration.useSurfaceView;
                              });
                            })
                      ],
                    ),
                  ),
                  Container(
                    padding: const EdgeInsets.all(16.0),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        const Text('disable TextureRender(for Android)'),
                        Switch(
                            value: GlobalConfiguration.closeTextureRender,
                            onChanged: (value) {
                              setState(() {
                                GlobalConfiguration.closeTextureRender = !GlobalConfiguration.closeTextureRender;
                              });
                            })
                      ],
                    ),
                  ),
                  Container(
                    padding: const EdgeInsets.all(16.0),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        const Text('enable preload and preRender strategy'),
                        Switch(
                            value: _sp?.getBool(GlobalConfigurationKey.engineStrategyEnabledKey) ?? false,
                            onChanged: (value) {
                              setState(() {
                                _enableEngineStrategy(value);
                                _sp?.setBool(GlobalConfigurationKey.engineStrategyEnabledKey, value);
                              });
                            })
                      ],
                    ),
                  ),
                  Container(
                    padding: const EdgeInsets.all(16.0),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        const Text('enable subtitle'),
                        Switch(
                            value: _sp?.getBool(GlobalConfigurationKey.subtitleEnabledKey) ?? false,
                            onChanged: (value) {
                              setState(() {
                                _sp?.setBool(GlobalConfigurationKey.subtitleEnabledKey, value);
                              });
                            })
                      ],
                    ),
                  ),
                  Container(
                    padding: const EdgeInsets.all(16.0),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        const Text('MDL 2.0 (need relaunch)'),
                        Switch(
                            value: _sp?.getBool(GlobalConfigurationKey.mdlV2EnabledKey) ?? false,
                            onChanged: (value) {
                              setState(() {
                                _sp?.setBool(GlobalConfigurationKey.mdlV2EnabledKey, value);
                              });
                            })
                      ],
                    ),
                  ),
                  Container(
                    padding: const EdgeInsets.all(16.0),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        const Text('clear cache'),
                        ElevatedButton(
                            onPressed: () => {TTVideoEnginePreload.clearAllCaches()},
                            child: const Text("click clear cache"))
                      ],
                    ),
                  ),
                ],
              ),
            )),
          ),
        ),
      ),
    );
  }

  void _didInputUrl(String url) {
    if (ShortVideoScene.sTestUrl != url) {
      ShortVideoScene.sTestUrl = url;
    }
  }

  void _didInputVid(String vid) {
    if (ShortVideoScene.sTestVid != vid) {
      ShortVideoScene.sTestVid = vid;
    }
  }

  void _didInputToken(String token) {
    if (ShortVideoScene.sTestToken != token) {
      ShortVideoScene.sTestToken = token;
    }
  }

  void _didInputSubtitleToken(String token) {
    if (ShortVideoScene.sTestSubtitleToken != token) {
      ShortVideoScene.sTestSubtitleToken = token;
    }
  }
}
3
likes
0
pub points
54%
popularity

Publisher

verified publishervolcengine.com

This Flutter plugin provides vod player sdk native APIs for you to implement video play functions in your application

Homepage

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on ve_vod