为什么just_audio Flutter Android模拟器不能播放来自流媒体服务的任何音频?

mcvgt66p  于 2023-10-22  发布在  Flutter
关注(0)|答案(1)|浏览(127)

以下代码(来自最终应用程序的片段)在iOS中运行良好,在Android Pixel 2 Simulator API 33上运行时没有任何错误。

import 'package:just_audio/just_audio.dart';
...
...
class _MyHomePageState extends State<MyHomePage> {
  late final WebViewController controller;

  final AudioPlayer player = AudioPlayer();

 @override
  void initState() {
    super.initState();

    controller = WebViewController()
      ..loadRequest(
        Uri.parse('https://renewfm.org/wp-content/themes/radiostation/showPlaying.php?device=web'),
      );

    //WidgetsBinding.instance.addPostFrameCallback( (_) async {
    //    await player.setUrl('https://renewfm.org/renewfm-stream.php');
    //    await player.play();
    //  }
    //);
    player.setUrl('https://renewfm.org/renewfm-stream.php');
    player.play();
  }
...

iOS开始播放它很好,有或没有WidgetsBinding.instance.addPostFrameCallback代码。Android的Android输出似乎表明它正在尝试播放:

D/BufferPoolAccessor2.0(19617): bufferpool2 0x77d419df0818 : 5(40960 size) total buffers - 1(8192 size) used buffers - 213/218 (recycle/alloc) - 5/432 (fetch/transfer)
D/BufferPoolAccessor2.0(19617): bufferpool2 0x77d419df0818 : 5(40960 size) total buffers - 1(8192 size) used buffers - 417/422 (recycle/alloc) - 5/840 (fetch/transfer)
...

但是没有音量。我把模拟器音量控制开了。
这是我的清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <application
        android:label="renewfm"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

谢谢你的帮助!

wmvff8tz

wmvff8tz1#

尝试它与不同的模拟器和它的工作。用API 33重试,成功了。想想吧。

相关问题