You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am currently working on implementing audio playback functionality in a Flutter app using the audioplayers plugin. However, I'm encountering an issue where the audio is not playing at all. Here's a simplified version of my code:
I am currently working on implementing audio playback functionality in a Flutter app using the audioplayers plugin. However, I'm encountering an issue where the audio is not playing at all. Here's a simplified version of my code:
dart
Copy code
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:audioplayers/audioplayers.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Audio Player Example'),
),
body: AudioPlayerWidget(),
),
);
}
}
class AudioPlayerWidget extends StatefulWidget {
@OverRide
_AudioPlayerWidgetState createState() => _AudioPlayerWidgetState();
}
class _AudioPlayerWidgetState extends State {
AudioPlayer player = AudioPlayer();
@OverRide
void initState() {
super.initState();
initPlayer();
}
Future initPlayer() async {
try {
print("Trying to play audio...");
await player.play(AssetSource('sounds/sample.wav'));
print("Audio playback started");
}
@OverRide
void dispose() {
player.dispose();
super.dispose();
}
@OverRide
Widget build(BuildContext context) {
return Container(
child: Center(
child: Text('Playing audio...'),
),
);
}
}
This is the code that I am using but it is audio is not getting Played.
The text was updated successfully, but these errors were encountered: