flutter_sound icon indicating copy to clipboard operation
flutter_sound copied to clipboard

[BUG]: PlatformException thrown when trying playing local audio file.

Open db-rdz opened this issue 3 years ago • 7 comments

Flutter Sound Version :

  • FULL v8.1.1

  • Important: Result of the command : flutter pub deps | grep flutter_sound

|-- flutter_sound 8.1.1 | |-- flutter_sound_platform_interface 8.1.1 | |-- flutter_sound_web 8.1.1 | | |-- flutter_sound_platform_interface...


Severity

  • Result is not what expected

Platforms you faced the error

  • Real iOS 14.5.1 device

Describe the bug

I need to download a remote audio file for editing. I'm using ffmpeg to cut and modify this audio and then I'm using FlutterSound to play the results.

The problme is that a PlatformException exception is thrown when I try to play the local .mp3 file that I downloaded. This exception only happens on a real device and not the emulator.

I was thinking that it could've been that I have two active players in the application but after changing to code to use only one the problem is still present. Remote audio files play just fine, the problem only appears when trying to play the file that I download. Once the problem appears the player fails to play remote or local files.

I'm using the following lines to play my audio files:

Future play(String filePath) {
  player.setSubscriptionDuration(_subscriptionHandler);
  return player.startPlayer(fromURI: filePath);
}

To Reproduce Steps to reproduce the behavior:

please allow give me a little bit of time to create a sample project that can reproduce this error.


Logs!!!!

(This is very important. Most of the time we cannot do anything if we do not have information on your bug)


flutter: FS:---> setSubscriptionDuration
flutter: FS:---> startPlayer
IOS:--> setSubscriptionDuration
IOS:--> setSubscriptionDuration
IOS:<-- setSubscriptionDuration
IOS:<-- setSubscriptionDuration
flutter: FS:---> stop
IOS:--> stopPlayer
IOS:--> stopPlayer
IOS:--> stopTimer
IOS:<-- stopTimer
IOS:<-- stopPlayer
IOS:<-- stopPlayer - status = 0
flutter: FS:<---- setSubscriptionDuration
flutter: FS:---> channelMethodCallHandler : stopPlayerCompleted
flutter: ---> stopPlayerCompleted: true
flutter: <--- stopPlayerCompleted: true
flutter: FS:<--- channelMethodCallHandler : stopPlayerCompleted
flutter: FS:<--- stop
flutter: FS:---> _convert
flutter: FS:---> needToConvert
flutter: FS:<--- needToConvert
flutter: FS:<--- _convert
IOS:--> startPlayer
IOS:--> startPlayer
IOS:--> stopTimer
IOS:<-- stopTimer
IOS:--> stopTimer
IOS:<-- stopTimer
IOS: ![audioPlayer stop]
IOS:<-- startPlayer
IOS:<-- startPlayer
[VERBOSE-2:ui_dart_state.cc(199)] Unhandled Exception: PlatformException(Audio Player, startPlayer failure, null, null)
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:597:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:158:18)
<asynchronous suspension>
#2      MethodChannelFlutterSoundPlayer.invokeMethod (package:flutter_sound_platform_interface/method_channel_flutter_sound_player.dart:184:12)
<asynchronous suspension>
#3      FlutterSoundPlayer._startPlayer (package:flutter_sound/public/flutter_sound_player.dart:1114:19)
<asynchronous suspension>
#4      FlutterSoundPlayer.startPlayer.<anonymous closure> (package:flutter_sound/public/flutter_sound_player.dart:1044:11)
<asynchronous suspension>
#5      BasicLock.synchronized (package:synchronized/src/basic_lock.dart:33:16)
<asynchronous suspension>
#6      FlutterSoundPlayer.startPlayer (package:flutter_sound/public/flutter_sound_player.dart:1043:5)
<asynchronous suspension>

db-rdz avatar May 20 '21 20:05 db-rdz

I'm have this error too :/

VeerneToor avatar May 29 '21 20:05 VeerneToor

I found what the problem was in my case but I haven’t found a good fix just a work around.

At least in my case the problem was with the initialization of the recorder and player. Opening the player before I open the recorder helped in my case but this is a work around instead of a fix and the error message is too general so it might be a total different thing for you

db-rdz avatar May 29 '21 21:05 db-rdz

I found my problem too :D, mi problem start with a directory of application, the app directory by a anonymous reason don't allowed write, I used the temporal directory for solve this problem

VeerneToor avatar May 30 '21 04:05 VeerneToor

I am also facing this issue. Is there any solution for this?

bilalgodesto avatar Jun 15 '21 05:06 bilalgodesto

am also facing this issue. Is there any solution for this?

anypwx avatar Aug 31 '21 07:08 anypwx

The problem is that a PlatformException exception is thrown when I try to play the local .mp3 file that I downloaded. This exception only happens on a real device and not the emulator.

Maybe you can look to #710 There is a problem with Flutter FFmpeg :

You must also check your build.gradle :

Remove any reference to repository jcenter() Add a reference to mavenCentral() if not already done

Larpoux avatar Sep 01 '21 08:09 Larpoux

How to play the local audio of the project. It's like using local pictures ??

huanlirui avatar Jan 27 '22 02:01 huanlirui

I'm also having the problem with a real Android device. The logs are not helpful and I don't know what to do... Has anyone found the solution?

AdrianBarcelo avatar Mar 17 '23 16:03 AdrianBarcelo

I was facing same issue with same package audioplayers. For android specific we need to configure path to access local media files from our devices.

For these I have used following dependencies:

  1. file_picker : <latest-version> (For picking file path)
  2. audioplayers: <latest-version> (For playing audio files)

To set custom path for getting local media file you need to put following code in your file:

pickSong() async {
    FilePickerResult? song = await FilePicker.platform.pickFiles(
      type: FileType.audio,
    );
    if (song != null) {
      var temp = song.files[0];
      songUrl = "file://${temp.path}";
      songName = songUrl.split("/").last;
      await player.setSourceUrl(songUrl);
      print(songUrl);
      duration = await player.getDuration();
      setState(() {});
    }
  }

The path for local media would look like : file:///data/user/0/com.example.ble_audioplayer/cache/file_picker/song_name.mp3

harsh11pujara avatar Apr 20 '23 12:04 harsh11pujara

This issue is stale because it has been open 90 days with no activity. Leave a comment or this will be closed in 7 days.

github-actions[bot] avatar Dec 16 '23 01:12 github-actions[bot]