The following code (snippet from the final app) works fine in iOS, and I don't get any errors when running it on 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 starts playing it fine, with or without the WidgetsBinding.instance.addPostFrameCallback
code. The Debug output for Android seems to indicate it is trying to play:
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)
...
But there's no volume. I have the simulator volume control up.
Here's my Manifest:
<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>
Thanks for the help!
Tried it with a different emulator and it worked. Retried it with the API 33 and it worked. Go figure.