flutter -- オーディオ プレーヤー audioplayers - プログラマー募集

サードパーティ製プラグインを使用してオーディオ再生を実現し、Android、IOS GitHub をサポート - rxlabz/audioplayer: オーディオ ファイルを再生するフラッター プラグイン iOS / Android / MacOS / Web ( Swift/Java ) icon-default.png?t=M0H8https://github.com/rxlabz /オーディオプレイヤー

ここにバグがあります

audioplayer: 0.8.1 のローカリゼーションが見つかりません

MethodChannel('bz.rxla.flutter/audio');

これに変更

audioplayer:
  パス: G:\ren_work\flutter\プロジェクト名\自分で書いたパッケージ名\audioplayer

使用法

このプラグインを使用するには:

  • 依存関係を pubspec.yaml ファイルに追加します。
 
    オーディオプレーヤー: 0.8.1
  
  • AudioPlayer インスタンスをインスタンス化する
//... 
AudioPlayer audioPlugin = AudioPlayer(); 
//...

プレーヤー コントロール

audioPlayer.play(url); 

audioPlayer.pause(); 

audioPlayer.stop();

ステータスと現在の位置

プラグインの dart 部分は、プラットフォーム コールをリッスンします。

//... 
_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);
    位置 = new Duration(seconds: 0); 
  }); 
});

ウィジェットが破棄されるときは、すべてのサブスクリプションをキャンセルすることを忘れないでください。

iOS

⚠️ iOS アプリ トランスポート セキュリティ

デフォルトでは、iOS は https 以外の URL からの読み込みを禁止しています。この制限をキャンセルするには、.plist を編集して以下を追加します。

<key>NSAppTransportSecurity</key> 
<dict> 
    <key>NSallowArbitraryLoads</key> 
    <true/> 
</dict>

バックグラウンド モード

参照。 バックグラウンド オーディオを有効にする

マックOS

これを資格ファイルに追加します (  DebugProfile.entitlementsを参照 )。

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

おすすめ

転載: blog.csdn.net/ren1027538427/article/details/122815182