Giter VIP home page Giter VIP logo

vlc-flutter's Introduction

vlc-flutter

This is a Flutter wrapper plugin for libvlc.See their website.

Todo:

  • Android
  • iOS

Usage

dependencies:
  vlc_flutter: ^0.0.2
import 'package:vlc_flutter/vlcplayer.dart';

Create VLCController:

// "-vvv" option
// print as detailed a log as possible for debugging purposes
VLCController _controller = VLCController(args:["-vvv"]);

Create a view for playback:

AspectRatio(
      aspectRatio: 16/9,
      child: VLCVideoWidget(
        controller: _controller,
      ),
    )

Play video according to uri:

ElevatedButton(
    child: Text("play"),
    onPressed: () async {
      await _controller.setDataSource(uri:"rtmp://58.200.131.2:1935/livetv/natlgeo");
      _controller.play();
    }),

Or just use the play:

_controller.play(uri:"rtmp://58.200.131.2:1935/livetv/natlgeo");

Play local resources:

_controller.play(path:"/sdcard/test/test.mp4");

Listening to the status of the player:

_controller.onPlayerState.listen((event) {
  debugPrint("=*= $event =*=");
});

Listening to player events:

_controller.onEvent.listen((event) {
    if(event.type == EventType.PositionChanged){
    	debugPrint("==[${event.positionChanged}]==");
    }
});

Add subtitles:

// Loading local subtitles
await _controller.addSlave(path: "/sdcard/test/Test.srt");
// Set the position of the subtitles
_controller.setVideoTitleDisplay(Position.Bottom, 1000);

Recorded video:

// Specify a directory and start recording
_controller.startRecord("/sdcard/test/");
// Stop Recording
_controller.stopRecord();

Don't forget to add network permissions to the AndroidManifest.xml to play network resources:

<uses-permission android:name="android.permission.INTERNET" />

If you need to record video, you may also need the following permissions:(These are dangerous permissions on Android 6.0 and above, so you may also need the flutter_easy_permission plugin)

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Example

class _MyAppState extends State<MyApp> {
  VLCController _controller = VLCController();

  @override
  void initState() {
    super.initState();

    _controller.onEvent.listen((event) {
      if(event.type == EventType.PositionChanged){
        debugPrint("==[${event.positionChanged}]==");
      }
    });
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('VLCPlayer Plugin example'),
        ),
        body: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            AspectRatio(
              aspectRatio: 16/9,
              child: VLCVideoWidget(
                controller: _controller,
              ),
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                ElevatedButton(
                    child: Text("play"),
                    onPressed: () async {
                      await _controller.setDataSource(
                          uri: "rtmp://58.200.131.2:1935/livetv/natlgeo");
                      _controller.play();
                    }),
                ElevatedButton(
                    child: Text("pause"),
                    onPressed: () {
                      _controller.pause();
                    }),
                ElevatedButton(
                    child: Text("stop"),
                    onPressed: () {
                      _controller.stop();
                    }),
                ElevatedButton(
                    child: Text("startRecord"),
                    onPressed: () {
                      _controller.startRecord("/sdcard/test/");
                    }),

                ElevatedButton(
                    child: Text("stopRecord"),
                    onPressed: () {
                      _controller.stopRecord();
                    })
              ],
            )
          ],
        ),
      ),
    );
  }
}

vlc-flutter's People

Contributors

arcticfox1919 avatar pinpong avatar abdelaziz-mahdy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.