How to Play M3U8 Format Android & iOS on Flutter

眉间皱痕 提交于 2020-12-05 10:21:30

问题


I can't find any solution for M3U8 Url player on iOS

I tried these plugins;

  • video_player (Can't play)
  • flutter_simple_video_player (Only support Android)

回答1:


chewie lib will be used for playing m3u8 files

Add Dependency

dependencies:
  chewie: ^0.9.10

Code Snippet:

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),
        ));
  }
}


来源:https://stackoverflow.com/questions/57682604/how-to-play-m3u8-format-android-ios-on-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!