Skip to content

Latest commit

 

History

History
345 lines (266 loc) · 8.68 KB

README.md

File metadata and controls

345 lines (266 loc) · 8.68 KB

Bringing power of VLC to Flutter & Dart apps on Windows & Linux

Installation

dependencies:
  ...
  dart_vlc: ^0.0.6

Support

Consider supporting the project by either/and:

  • ⭐ Starring the repository, to get this hardwork noticed.
  • ☕ Buying me a coffee.

Documentation

Create a new player instance.

Player player = new Player(id: 69420);

Create a media for playback.

Media media0 = await Media.file(
  new File('C:/music.mp3')
);

Media media1 = await Media.network(
  'https://www.example.com/music.aac'
);

Media media2 = await Media.asset(
  'assets/music.ogg'
);

Create a list of medias using playlist.

Playlist playlist = new Playlist(
  medias: [
    await Media.file(new File('C:/music.mp3')),
    await Media.asset('assets/music.ogg'),
    await Media.network('https://www.example.com/music.aac'),
  ],
);

Open a media or playlist into a player.

player.open(
  new Playlist(
    medias: [
      await Media.file(new File('C:/music0.mp3')),
      await Media.file(new File('C:/music1.mp3')),
      await Media.file(new File('C:/music2.mp3')),
    ],
  ),
  autoStart: true, // default
);

Control playback.

player.play();

player.seek(Duration(seconds: 30));

player.pause();

player.playOrPause();

player.stop();

Manipulate an already playing playlist.

player.add(
  await Media.file(new File('C:/music0.mp3')),
);

player.remove(4);

player.insert(
  2,
  await Media.file(new File('C:/music0.mp3')),
);

player.move(0, 4);

Set playback volume & rate.

player.setVolume(0.5);

player.setRate(1.25);

Get & change playback device.

List<Device> devices = await Devices.all;

player.setDevice(
  devices[0],
);

Show the video inside widget tree.

Instanciate Player as follows.

Player player = new Player(
  id: 69420,
  videoWidth: 480,
  videoHeight: 320,
);

Show Video in the Widget tree.

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Video(
        playerId: 69420,
        height: 1920.0,
        width: 1080.0,
        scale: 1.0, // default
        showControls: false, // default
      ),
    );
  }
}

Thanks to @tomassasovsky for adding visual controls to Video widget.

Retrieve metadata of media.

Media media = await Media.network(
  'https://www.example.com/media.mp3',
  parse: true,
  timeout: new Duration(seconds: 10),
);

Map<String, String> metas = media.metas;

Listen to playback events.

(Same can be retrieved directly from Player instance without having to rely on stream).

player.currentStream.listen((CurrentState state) {
  state.index;
  state.media;
  state.medias;
  state.isPlaylist;
});
player.positionStream.listen((PositionState state) {
  state.position;
  state.duration;
});
player.playbackStream.listen((PlaybackState state) {
  state.isPlaying;
  state.isSeekable;
  state.isCompleted;
});
player.generalStream.listen((GeneralState state) {
  state.volume;
  state.rate;
});

Broadcast a media.

Broadcasting to localhost.

Broadcast broadcast = await Broadcast.create(
  id: 0,
  media: await Media.file(new File('C:/video.mp4')),
  configuration: new BroadcastConfiguration(
    access: 'http',
    mux: 'mpeg1',
    dst: '127.0.0.1:8080',
    vcodec: 'mp1v',
    vb: 1024,
    acodec: 'mpga',
    ab: 128,
  ),
);
broadcast.start();

Dispose the Broadcast instance to release resources.

broadcast.dispose();

Record a media.

Thanks to @DomingoMG for adding Record and Chromecast classes.

Record record = await Record.create(
  id: 205, 
  media: await Media.network('https://www.example.com/streaming-media.MP3'), 
  pathFile: '/home/alexmercerind/recording.MP3',
);
record.start();

NOTE: For using this plugin on Linux, you must have VLC & libVLC installed. On debian based distros, run:

sudo apt-get install vlc
sudo apt-get install libvlc-dev

Example

You can see an example project here.

Windows

Workings

The internal wrapper used in the plugin is here in the repository (Based on libVLC++). It makes handling of events and controls a lot easier & has additional features to it.

Same wrapper will be used for upcoming FFI version.

I preferred to do majority of plugin handling in C++ itself, thus Dart code is minimal & very slight mapping to it.

Progress

Done

  • Media playback from File.
  • Media playback from network.
  • Media playback from assets.
  • play/pause/playOrPause/stop.
  • Multiple Player instances.
  • Playlist.
  • next/back/jump for playlists.
  • setVolume.
  • setRate.
  • seek.
  • Events.
  • Automatic fetching of headers, libs & shared libraries.
  • Changing VLC version from CMake.
  • Event streams.
    • Player.currentState
      • index: Index of current media in Playlist.
      • medias: List of all opened Medias.
      • media: Currently playing Media.
      • isPlaylist: Whether a single Media is loaded or a Playlist.
    • Player.positionState
      • position: Position of currently playing media in Duration.
      • duration: Position of currently playing media in Duration.
    • Player.playbackState
      • isPlaying.
      • isSeekable.
      • isCompleted.
    • Player.generalState
      • volume: Volume of current Player instance.
      • rate: Rate of current Player instance.
  • add/insert/remove/move Media inside Playlist during playback.
  • Device enumeration & changing.
  • Retrieving Meta of a Media.
  • Embedding Video inside the Flutter window.
  • Supporting live streaming links.
  • Broadcast class for broadcasting Media.
  • Record class for recording Media.
  • Chromecast class.

Under progress or planned features (irrespective of order)...

  • FFI version of the library for plain Dart applications.
  • Removing libVLC++ dependency. (Maybe).
  • Writing metadata tags.
  • Making things more efficient.
  • Supporting native volume control/lock screen notifications (Maybe).
  • Bringing project on other platforms like Android/iOS (Maybe).
  • Adding headers for MRLs (Maybe).
  • D-Bus MPRIS controls for Media playback control (Maybe).

Acknowledgements

First of all, thanks to the VideoLAN team for creating libVLC & libVLC++. Really great guys really great at their work.

Thanks to following members of libVLC community to give me bit of look & advice about how things work:

Massive thanks to @stuartmorgan from Flutter team to review code & help me fix the loopholes.

Contributions

The code in the project is nicely arranged (I guess), I have added comments wherever I felt necessary.

Contributions to the project are open, it will be appreciated if you discuss the bug-fix/feature-addition in the issues first.

License

Copyright (C) 2021, Hitesh Kumar Saini, Domingo Montesdeoca Gonzalez & contributors.

This library & work under this repository is licensed under GNU Lesser General Public License v2.1.

Vision

There aren't any media (audio or video) playback libraries for Flutter on Windows/Linux yet. So, this project is all about that. As one might be already aware, VLC is one of the best media playback tools out there.

So, now you can use it to play audio or video files from Flutter Desktop apps.

Although, the mentioned repositories above are for audio playback, video playback is also a part of consideration for this project.