audio_service icon indicating copy to clipboard operation
audio_service copied to clipboard

Local file ArtUri not showing in iOS

Open arshrahman opened this issue 3 years ago • 13 comments

Which API doesn't behave as documented, and how does it misbehave? local artfile doesn't show in iOS. Web url works in iOS. Both local and web artUri is working in Android

Minimal reproduction project Save an image to the NSApplicationSupportDirectory of iOS. This can be done by calling getApplicationSupportDirectory() function of path_provider package.

example local artUri file in iOS: file:///var/mobile/Containers/Data/Application/4CF715DR-502C-4B98-A41C-8EA319821SE6/Library/Application%20Support/category/1.png Set MediaItem artUri to the local file Uri. Art Uri doesn't show in iOS media notification.

Here's a minimal code to copying an asset image to NSApplicationSupportDirectory of iOS and get the uri.

  1. Add path_provider: ^2.0.1 to pubspec.yaml
  2. Add asset image to 'pubspec.yaml'
  assets:
    - assets/category/1.png
Future<String> saveImagetoDevice() async {
    final path = join((await getApplicationSupportDirectory()).path, 'category', '1.png');
    if (FileSystemEntity.typeSync(path) == FileSystemEntityType.notFound) {
        final byteData = await rootBundle.load('assets/category/1.png');
        final bytes = byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes);
        await File(path).create(recursive: true)
          ..writeAsBytes(bytes);
    }
    return path;
}
final artUri = await saveImagetoDevice();
AudioService.updateQueue([    
MediaItem(
      id: "https://s3.amazonaws.com/scifri-segments/scifri201711241.mp3",
      album: "Science Friday",
      title: "From Cat Rheology To Operatic Incompetence",
      artist: "Science Friday and WNYC Studios",
      duration: Duration(milliseconds: 2856950),
      artUri: artUri
)]);

To Reproduce (i.e. user steps, not code) Steps to reproduce the behavior:

  1. Set the MediaItem to local artUri
  2. Play the MediaItem
  3. iOS doesn't show the artUri

Expected behavior local artUri should also show in iOS media notification

Runtime Environment (please complete the following information if relevant):

  • Device: iPhone 11
  • OS: iOS 14.5

Flutter SDK version

insert output of "flutter doctor" here
[✓] Flutter (Channel stable, 1.22.5, on macOS 11.0.1 20B29 darwin-x64, locale en-SG)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 12.5)
[✓] Android Studio (version 3.6)
[✓] VS Code (version 1.54.3)

Package Version

just_audio: ^0.6.13
audio_service: ^0.16.2

arshrahman avatar Mar 19 '21 03:03 arshrahman

Minimal reproduction project Save an image to the NSApplicationSupportDirectory of iOS. This can be done by calling getApplicationSupportDirectory() function of path_provider package.

Can you do that and then provide me with a link that I can clone and run?

ryanheise avatar Mar 19 '21 06:03 ryanheise

Here's a minimal project setup reproducing the error: https://github.com/arshrahman/audio_service

I just basically modified the example audio_service project to get a local artUri for the first MediaItem in the MediaLibrary class. All the changes are only in MediaLibrary class. There are two MediaItems. The first one has a local art uri and the second one has web image url. Both images are shown in Android media notification. However, only the web image is shown for iOS media notification.

arshrahman avatar Mar 19 '21 08:03 arshrahman

Thanks, @arshrahman . Just to check, are you testing on a Simulator or an actual iPhone device?

ryanheise avatar Mar 19 '21 08:03 ryanheise

Because there is a space in Application%20Support it is getting URL-encoded. But I'm not sure if the path on a real iPhone device will have the same problem.

My focus is now on the upcoming 0.18.0 release which should already have this bug fixed, so if it is urgent for you, you may consider trying this out in its preview form.

ryanheise avatar Mar 19 '21 09:03 ryanheise

I am using an actual iPhone device. iPhone 11 model. Actually, in the iOS simulator, the media notification doesn't show at all. Not sure, if i need to turn on some setting to show the media notification

arshrahman avatar Mar 19 '21 09:03 arshrahman

I see. On the simulator it was possible to test these things using an older version of Xcode but this can't be used on the BigSur. But as per your answer, the bug is present on both the simulator and real devices.

As before, I would suggest trying out the upcoming 0.18.0 release if it is urgent for you.

ryanheise avatar Mar 19 '21 09:03 ryanheise

I see, I am running Bug Sur. I will try out 0.18.0 release a little later as it needs some migration. This is a minor bug and it doesn't affect the functionality.

arshrahman avatar Mar 19 '21 09:03 arshrahman

Test below code:

final artUri = await saveImagetoDevice(); AudioService.updateQueue([
MediaItem( * * artUri: "file://$artUri" )]);

zhouyuanbo avatar Aug 31 '21 14:08 zhouyuanbo

@zhouyuanbo have you read my previous comment?

ryanheise avatar Aug 31 '21 14:08 ryanheise

@arshrahman can you confirm whether the issue persists in 0.18.0?

ryanheise avatar Sep 01 '21 05:09 ryanheise

I was trying artUri: Uri.file('assets/path-to-local-file.png') on just_audio_background: 0.0.1-beta.1. Unfortunately the album art does not show up.

edit: it seems that I am trying to achieve something else. I would like to use an image asset bundled with the app. For those assets one can not obtain a path.

In addition to that Uri.file does not do what I thought it would do, but creates a new file 🙃

ma-pe avatar Nov 07 '21 19:11 ma-pe

@ma-pe have you found any solution to show artUri from assets folder?

sanjay23singh avatar Nov 16 '21 14:11 sanjay23singh

@sanjay23singh that is not related to this issue. Please search for another existing issue for loading the artUri from assets, or if one does not exist, submit one.

ryanheise avatar Nov 17 '21 01:11 ryanheise