Coder Social home page Coder Social logo

lxw5689 / audioplayer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rxlabz/audioplayer

0.0 0.0 0.0 13.4 MB

A flutter plugin to play audio files iOS / Android / MacOS / Web ( Swift/Java )

Home Page: https://pub.dartlang.org/packages/audioplayer

Java 16.44% Ruby 6.46% Objective-C 4.51% Dart 46.00% Swift 22.26% Shell 1.22% HTML 3.12%

audioplayer's Introduction

AudioPlayer

A Flutter audio plugin (Swift/Java) to play remote or local audio files on iOS / Android / MacOS and Web.

Online demo

Features

  • Android / iOS / MacOS / Web
    • play remote file
    • play local file ( not for the web)
    • stop
    • pause
    • onComplete
    • onDuration / onCurrentPosition
    • seek
    • mute

screenshot

Usage

Example

To use this plugin :

  dependencies:
    flutter:
      sdk: flutter
    audioplayer: 0.8.1
    audioplayer_web: 0.7.1
  • Instantiate an AudioPlayer instance
//...
AudioPlayer audioPlugin = AudioPlayer();
//...

Player Controls

audioPlayer.play(url);

audioPlayer.pause();

audioPlayer.stop();

Status and current position

The dart part of the plugin listen for platform calls :

//...
_positionSubscription = audioPlayer.onAudioPositionChanged.listen(
  (p) => setState(() => position = p)
);

_audioPlayerStateSubscription = audioPlayer.onPlayerStateChanged.listen((s) {
  if (s == AudioPlayerState.PLAYING) {
    setState(() => duration = audioPlayer.duration);
  } else if (s == AudioPlayerState.STOPPED) {
    onComplete();
    setState(() {
      position = duration;
    });
  }
}, onError: (msg) {
  setState(() {
    playerState = PlayerState.stopped;
    duration = new Duration(seconds: 0);
    position = new Duration(seconds: 0);
  });
});

Do not forget to cancel all the subscriptions when the widget is disposed.

iOS

โš ๏ธ iOS App Transport Security

By default iOS forbids loading from non-https url. To cancel this restriction edit your .plist and add :

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

Background mode

cf. enable background audio

MacOS

Add this to entitlements files ( cf. DebugProfile.entitlements )

    <key>com.apple.security.network.client</key>
    <true/>

cf. Flutter MacOS security

Troubleshooting

  • If you get a MissingPluginException, try to flutter build apk on Android, or flutter build ios

Getting Started with Flutter

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

audioplayer's People

Contributors

rxlabz avatar mehmetf avatar mattetti avatar mindon avatar oakes avatar alanrussian avatar gdcolella avatar josh-burton avatar lidongze91 avatar mit-mit avatar mhatout avatar nstrelow 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.