Search code examples
flutterdartaudio

How to play m3u8 audio file in Flutter?


Don't know how to play m3u8 audio file in Flutter. I searched for information about this, but what I found either did not work or was useless. Help please!

P.S: I need this to work on Windows too.


Solution

  • m3u8 is not an audio file - it's a text file with links pointing to the actual files.

    That said, I think chewie can help you.

    You just need to install and import the package, then put a controller like this somewhere:

    import 'package:flutter/material.dart';
    import 'package:chewie/chewie.dart';
    import 'package:video_player/video_player.dart';
    
    void main() {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
        const MyApp({Key? key}) : super(key: key);
    
        final videoPlayerController = VideoPlayerController.network('your.m3u8');
        ChewieController chewieController;
    
        @override
        void initState() {
            super.initState();
            chewieController = ChewieController(
                videoPlayerController: videoPlayerController,
            );
        }
    
        @override
        Widget build(BuildContext context) {
            return Scaffold(
                appBar: AppBar(
                    title: Text("Flutter Demo"),
                ),
                body: Container(
                    child: Chewie(controller: chewieController),
                )
            );
        }
    }
    
    

    I'm sure there'll be more documentation for your specific use case. There are settings like autoPlay, aspectRatio, and so on.

    Hope this helps.