0

How to use Audio_service playing URL link which will be obtained from API. Ex: Use _player.setAudioSource(AudioSource.uri(Uri.parse(URL))); where URL will be obtained from http.Response

Please help me I need to get Url String from internet, and need to play it with AndroidHandler()

Code :

...

late AudioHandler _audioHandler;

Future<void> main() async {
  _audioHandler = await AudioService.init(
    builder: () => AudioPlayerHandler(),
    config: const AudioServiceConfig(
      androidNotificationChannelId: 'com.ryanheise.myapp.channel.audio',
      androidNotificationChannelName: 'Audio playback',
      androidNotificationOngoing: true,
    ),
  );
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  ...
}

class AudioPlayerHandler extends BaseAudioHandler{
  
  ...
  final _player = AudioPlayer();

  /// Initialise our audio handler.
  AudioPlayerHandler() {
    // Load the player.
    _player.setAudioSource(AudioSource.uri(Uri.parse(url)));
  }
}




Wisdom
  • 1
  • 1

0 Answers0