• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

rxlabz/audioplayer: A flutter plugin to play audio files iOS / Android / MacOS / ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

rxlabz/audioplayer

开源软件地址(OpenSource Url):

https://github.com/rxlabz/audioplayer

开源编程语言(OpenSource Language):

Dart 46.0%

开源软件介绍(OpenSource 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.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
williambout/paper-for-mac: 发布时间:2022-08-18
下一篇:
nihui/opencv-mobile: The minimal opencv for Android, iOS, ARM Linux, Windows, Li ...发布时间:2022-08-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap