-
Notifications
You must be signed in to change notification settings - Fork 28
Description
Can we access your project?
- I give permission for members of the FlutterFlow team to access and test my project for the sole purpose of investigating this issue.
Current Behavior
If I create a custom code called playSound using the import 'package:audioplayers/audioplayers.dart'; and try to run it, it cannot find my sound files.
Expected Behavior
I expect the custom code to play my music file in the background.
Steps to Reproduce
Create a new project
Add the audioplayers library version 6.0.0 to dependencies
Create the following custom code called playSound:
// Automatic FlutterFlow imports
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:audioplayers/audioplayers.dart';
Future playSound(
String audioPath,
bool isUrl,
) async {
AudioPlayer player;
// Add your function code here!
audioPath = 'assets/audios/ocean_waves.mp3';
try {
// Validate input
if (audioPath.isEmpty) {
print('Error: Audio path is empty');
return false;
}
// Create audio player instance
player = AudioPlayer();
if (isUrl) {
// Play from URL
print('Attempting to play from URL: $audioPath');
await player.play(UrlSource(audioPath));
print('URL audio played successfully');
} else {
// Play from assets
//String fullPath = audioPath.startsWith('assets/')
// ? audioPath
// : 'assets/audios/$audioPath';
//String assetSourcePath =
// fullPath.startsWith('assets/') ? fullPath.substring(7) : fullPath;
print('Attempting to play from assets: $audioPath');
await player.play(AssetSource(audioPath));
print('Asset audio played successfully');
}
return true;
} catch (e, stackTrace) {
print('Error playing sound: $e');
print('Stack trace: $stackTrace');
return false;
}
}
On page load, call the custom code playSound.
It will not find the music file.
Reproducible from Blank
- The steps to reproduce above start from a blank project.
Bug Report Code (Required)
IT4kj8nlz5F2rt9c187pbfoxjSosKW1/TLJEpu0bWUkbGO/4B7Midc77TBZvXcyzaHNYHGGYijkF+vTGi+PxVPUBAwSuG9xy+s5QcxPPbGWnbpSRPJCSOkR8DflVCh2l16aN2QhAXLduSkYW3E76NeSXEj6Cf9qOYwx5e6fDbOY=
Visual documentation
There are no images to show. Please refer to my notes and try to run my project.
Environment
- FlutterFlow version: 6.4.21
- Platform: Mobile (Android OS)
- Browser name and version: Google Chrome v142.0.7444.60
- Operating system and version affected: MacOS Sequoia 15.6.1 (24G90)Additional Information
No response