media_player 0.0.7

media_player(android support only) #

This media player uses an google Exoplayer in android to play the media files.

Note: the media player is inspired and developer by google plugin video_player and uses most code of it and has extra features.

If you don't want to bother with implementing ui widgets and need a readymade video player Please visit http://flutter-media-player.cf

Github Link : https://github.com/siddhesh-tamhanekar/media_player

Getting Started Tutorial at medium: https://medium.com/google-exoplayer/dynamic-playlists-with-exoplayer-6f53e54a56c0

Please subscribe to our mailing list for get new updates. https://goo.gl/forms/RTnApDBve4scuUAu2

Features #

  • Can play Audio and Video File URLs (mp3, mp4, m3u8 etc)
  • Playlist Support
  • Single Media File Play Support
  • Control over player (play, pause, next, prev, seek etc.)
  • can be used to create background player(mostly used for audio playing).
  • Persistent Notification
  • Retry method in order to make player start from where left (if internet connection was problem)

Screenshots #

Getting Started #

STEP 1: add dependancy into pubspec.yaml file #

STEP 2: Add following code into AndroidManifest.xml #

Add service android/app/AndroidManifest.xml

<service
    android:name="com.example.mediaplayer.AudioService"
    android:enabled="true"
    android:exported="false">
</service>

Add the permission for foreground service in same AndroidManifest.xml .

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

STEP 3: Add the following dependency into android/app/build.graddle #

    android {
            compileOptions {
                sourceCompatibility JavaVersion.VERSION_1_8
                targetCompatibility JavaVersion.VERSION_1_8
            }
    }

Simple Example #

import 'package:flutter/material.dart';
import 'package:media_player/data_sources.dart';
import 'package:media_player/media_player.dart';
import 'package:media_player/ui.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: MyVideoScreen(),
      ),
    );
  }
}

class MyVideoScreen extends StatefulWidget {
  @override
  _MyVideoScreenState createState() => _MyVideoScreenState();
}

class _MyVideoScreenState extends State<MyVideoScreen> {
  MediaPlayer player;
  MediaFile song1 = MediaFile(
    title: "Song 1",
    type: "video",
    source: "http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8",
    desc: "Note from Apple",
  );

  @override
  void initState() {
    // first argument for isBackground next for showNotification.
    player = MediaPlayerPlugin.create(isBackground: true, showNotification: true);
    initVideo();
    super.initState();
  }

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

  void initVideo() async {
    await player.initialize();
    await player.setSource(song1);
    player.play();
  }

  @override
  Widget build(BuildContext context) {
    return Column(children: [
      VideoPlayerView(player),
      VideoProgressIndicator(
        player,
        allowScrubbing: true,
         padding: EdgeInsets.symmetric(vertical:5.0),
      ),
      SizedBox(height:20.0),
      buildButtons()
    ]);
  }

  Row buildButtons() {
    return Row(
      children: <Widget>[
        FlatButton(
          child: Text("Prev"),
          onPressed: () {
            player.playPrev();
          },
        ),
        FlatButton(
          child: Text("Play"),
          onPressed: () {
            player.play();
          },
        ),
        FlatButton(
          child: Text("Pause"),
          onPressed: () {
            player.pause();
          },
        ),
        FlatButton(
          child: Text("Next"),
          onPressed: () {
            player.playNext();
          },
        ),
      ],
    );
  }
}


0.0.1 #

  • TODO: Describe initial release.

0.0.2 #

  • TODO:: updated readme.

0.0.3 #

  • TODO:: updated readme.

0.0.4 #

Added retry method Fixed Bugs for fast forward and rewind.

0.0.5 #

Fixed Bug Service remains started even app is closed.

0.0.6 #

Fixed Bug Audio remains started even app is closed.

0.0.7 #

Fixed Bug of negative duration when track is changed.

example/README.md

media_player_example #

Demonstrates how to use the media_player plugin.

If you don't want to bother with implementing ui widgets and need a readymade video player UI, visit the http://flutter-media-player.cf

Simple Example #

import 'package:flutter/material.dart';
import 'package:media_player/data_sources.dart';
import 'package:media_player/media_player.dart';
import 'package:media_player/ui.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: MyVideoScreen(),
      ),
    );
  }
}

class MyVideoScreen extends StatefulWidget {
  @override
  _MyVideoScreenState createState() => _MyVideoScreenState();
}

class _MyVideoScreenState extends State<MyVideoScreen> {
  MediaPlayer player;
  MediaFile song1 = MediaFile(
    title: "Song 1",
    type: "video",
    source: "http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8",
    desc: "Note from Apple",
  );

  @override
  void initState() {
    // first argument for isBackground next for showNotification.
    player = MediaPlayerPlugin.create(isBackground: true, showNotification: true);
    initVideo();
    super.initState();
  }

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

  void initVideo() async {
    await player.initialize();
    await player.setSource(song1);
    player.play();
  }

  @override
  Widget build(BuildContext context) {
    return Column(children: [
      VideoPlayerView(player),
      VideoProgressIndicator(
        player,
        allowScrubbing: true,
         padding: EdgeInsets.symmetric(vertical:5.0),
      ),
      SizedBox(height:20.0),
      buildButtons()
    ]);
  }

  Row buildButtons() {
    return Row(
      children: <Widget>[
        FlatButton(
          child: Text("Prev"),
          onPressed: () {
            player.playPrev();
          },
        ),
        FlatButton(
          child: Text("Play"),
          onPressed: () {
            player.play();
          },
        ),
        FlatButton(
          child: Text("Pause"),
          onPressed: () {
            player.pause();
          },
        ),
        FlatButton(
          child: Text("Next"),
          onPressed: () {
            player.playNext();
          },
        ),
      ],
    );
  }
}


Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  media_player: ^0.0.7

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:media_player/media_player.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
83
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
89
Learn more about scoring.

We analyzed this package on Jul 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8

Admin