byteplus_live 1.47.300 copy "byteplus_live: ^1.47.300" to clipboard
byteplus_live: ^1.47.300 copied to clipboard

ve live flutter sdk

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:byteplus_live/velive_flutter_sdk.dart';
import 'play_page.dart';
import 'multi_instance_page.dart';
import 'setting_page.dart';
import 'package:byteplus_live_platform/velive_flutter_sdk_platform_interface.dart';
// import 'package:mobile_scanner/mobile_scanner.dart';
import 'widgets/qr_scan_input.dart';
import 'config/config.dart';

void main() {
  runApp(const MyApp());
}

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

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

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    print(VeLiveFlutterSDKPlatformInterface.isOhos ? "Ohos" : "Android or iOS");

    TTSDKConfiguration config = TTSDKConfiguration(
      appID: AppConfig.appID,
      bundleID: AppConfig.bundleID,
      appName: AppConfig.appName,
      channel: AppConfig.channel,
      licenseFilePath: AppConfig.licenseFilePath,
    );

    VeLivePlayer.startWithConfiguration(config);

    VeLivePlayer.getDid().then((did) {
      print('player did: $did');
    }).catchError((error) {});

    VeLivePlayer.getVersion().then((version) {
      print('PlayerVersion: $version');
    }).catchError((error) {});
  }

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: ListPage(),
    );
  }
}

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

  @override
  State<ListPage> createState() => _ListPageState();
}

class _ListPageState extends State<ListPage> {
  final TextEditingController _editingController = TextEditingController();
  final TextEditingController _editingController2 = TextEditingController();
  final TextEditingController _textController = TextEditingController();

  // MobileScannerController scannerController = MobileScannerController();

  @override
  void initState() {
    super.initState();
    _editingController.text =
        'http://pull-demo.volcfcdnrd.com/live/st-4536525.flv';
    _editingController2.text = '';
    _textController.text = '';
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('app'),
      ),
      body: ListView(
        children: [
          QrScanInput(
            controller: _editingController,
          ),
          ElevatedButton(
              onPressed: () {
                Navigator.of(context).push<SettingConfiguration>(
                    MaterialPageRoute(builder: (ctx) {
                  return const SettingPage();
                }));
              },
              child: const Text(
                'Setting',
                style: TextStyle(fontSize: 22),
              )),
          ElevatedButton(
              onPressed: () {
                var text = _editingController.text;
                if (text.isEmpty) {
                  Fluttertoast.showToast(
                    msg: '请输入流地址1',
                    gravity: ToastGravity.CENTER,
                  );
                  return;
                }
                Navigator.push(context, MaterialPageRoute(builder: (ctx) {
                  return PlayPage(playUrl: text);
                }));
              },
              child: const Text(
                '一个实例',
                style: TextStyle(fontSize: 22),
              )),
          const SizedBox(height: 40),
          Container(
            padding: const EdgeInsets.only(left: 15, right: 15, bottom: 10),
            child: QrScanInput(
              controller: _editingController2,
              labelText: '需要两个流地址, 流地址1和流地址2都要填写',
              hintText: '请输入流地址2',
              labelStyle: const TextStyle(color: Colors.red),
              hintStyle: const TextStyle(color: Colors.grey, fontSize: 16),
            ),
          ),
          ElevatedButton(
              onPressed: () async {
                var text = _editingController.text;
                if (text.isEmpty) {
                  Fluttertoast.showToast(
                    msg: '请输入流地址1',
                    gravity: ToastGravity.CENTER,
                  );
                  return;
                }

                var text2 = _editingController2.text;
                if (text2.isEmpty) {
                  Fluttertoast.showToast(
                    msg: '请输入流地址2',
                    gravity: ToastGravity.CENTER,
                  );
                  return;
                }

                FocusScope.of(context).unfocus();

                Navigator.of(context).push(MaterialPageRoute(builder: (ctx) {
                  return MultiInstancePage(
                    playUrl: text,
                    playUrl2: text2,
                  );
                }));
              },
              child: const Text(
                '多实例',
                style: TextStyle(fontSize: 22),
              )),
        ],
      ),
    );
  }

  @override
  void dispose() {
    _textController.dispose();
    // 新增:释放所有 TextEditingController
    _editingController.dispose();
    _editingController2.dispose();
    super.dispose();
  }
}