ve_vod 1.0.1-premium ve_vod: ^1.0.1-premium copied to clipboard
This Flutter plugin provides vod player sdk native APIs for you to implement video play functions in your application
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> {
final _vodPlayerFlutterPlugin = VodPlayerFlutter();
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 {
// 打开日志开关
await FlutterTTSDKManager.openAllLog();
// 注册插件日志
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.appRegion = TTSDKServiceVendor.TTSDKServiceVendorCN;
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();
print("TTF -- uniqueId:$uniqueID deviceId:$deviceID");
if (!mounted) return;
setState(() {});
}
@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: 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: '输入测试地址',
),
keyboardType: TextInputType.url,
textInputAction: TextInputAction.done,
)),
Container(
padding: const EdgeInsets.all(16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text('iOS开启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('硬解播放'),
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('打开:调节播放音量,关闭:调节系统音量'),
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(仅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('关闭TextureRender(仅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('MDL 2.0 (重启生效)'),
Switch(
value: _sp?.getBool(
GlobalConfigurationKey.mdlV2EnabledKey) ??
false,
onChanged: (value) {
setState(() {
_sp?.setBool(
GlobalConfigurationKey.mdlV2EnabledKey,
value);
});
})
],
),
),
ElevatedButton(
onPressed: () {
String url = ShortVideoScene.sTestUrl;
assert(url.isNotEmpty, '请传入有效的测试地址');
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const ShortVideoScene(),
),
);
},
child: const Text("小视频")),
ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const VideoPreload(),
),
);
},
child: const Text("预加载")),
],
),
),
),
),
),
);
}
void _didInputUrl(String url) {
if (ShortVideoScene.sTestUrl != url) {
ShortVideoScene.sTestUrl = url;
}
}
}