如何在Flutter上播放M3U8格式的Android和iOS

sdnqo3pr  于 2023-05-08  发布在  Flutter
关注(0)|答案(3)|浏览(420)

我找不到iOS上M3U8 URL播放器的任何解决方案
我尝试了这些插件;

  • video_player(无法播放)
  • flutter_simple_video_player(仅支持Android)
wfauudbj

wfauudbj1#

chewie库将用于播放m3u8文件

添加依赖关系

dependencies:
  chewie: ^0.9.10

代码段:

import 'package:flutter/material.dart';
import 'package:chewie/chewie.dart';
import 'package:video_player/video_player.dart';

void main() {
  runApp(MaterialApp(home: MyApp()));
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final videoPlayerController = VideoPlayerController.network(
      'url.m3u8');
  ChewieController chewieController;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    chewieController = ChewieController(
      videoPlayerController: videoPlayerController,
      aspectRatio: 3 / 2,
      autoPlay: true,
      looping: true,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("Sample App"),
        ),
        body: Container(
          child: Chewie(controller: chewieController),
        ));
  }
}
csga3l58

csga3l582#

yoyo播放器是最好的选择,但这个包不支持你的项目,你可以使用这个包,我改变了yaml和更新这个包,为更新Flutter,

yoyo_player:
    git:
      url: https://github.com/AmiirTorabii/yoyo_player_update

它为我工作:)

hlswsv35

hlswsv353#

YoYo player是一个很好的选择。
1.添加依赖关系:
yoyo_player: #latest
1.在任何你想要的地方使用:

YoYoPlayer(
       aspectRatio: 16 / 9,
       url:  "",
       videoStyle: VideoStyle(),
       videoLoadingStyle: VideoLoadingStyle(),
  ),

相关问题