I'm learning to use Flutter in FlutterFlow and working on a custom function that plays mp3s from a link. I'm using the Assets Audio Player library.
When I call the function I can get the audio to play but I can't get it to pause when I call it again- I'm using the PlayOrPause action. I suspect it's because I'm not referencing the paying instance- but how do I do that?
Here's my code:
// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/backend/supabase/supabase.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
import 'package:assets_audio_player/assets_audio_player.dart';
Future assetsAP() async {
// Add your function code here!
var assetsAP = AssetsAudioPlayer.withId("0");
try {
await assetsAP.open(
Audio.network(
"https://firebasestorage.googleapis.com/v0/b/king-a1558.appspot.com/o/users%2F191vQKCdf8eBy1%2Fuploads%2F1674554237169000.mp3?"),
autoStart: false,
);
} catch (t) {
//mp3 unreachable
}
assetsAP.playOrPause();
}