phiamo / capacitor-plugin-playlist

A capacitor migration of cordova-plugin-playlist
27 stars 20 forks source link

iOS, playing local files how can we set content type #59

Closed timstoute closed 2 years ago

timstoute commented 2 years ago

I'm trying to play a local file resource, with a uri like:

file:///var/mobile/Containers/Data/Application/C52537C1-6DDE-438B-AFC4-243C526143D0/Documents/a65c53f77de85cce59b536502b5c3b99

I'm getting error:

RmxAudioPlayer.onStatus: Error(5) [a65c53f77de85cce59b536502b5c3b99]: {"code":3,"message":"Error playing audio track: This media format is not supported."}

I suspect that this is because the Content Type is incorrect or not specified. My local file is an audio/mpeg content type.

How can I set this in the plugin or successfully play this local file?

phiamo commented 2 years ago

If i remember correctly i remove file:// at the path.. but i need to check

Tim Stoute @.***> schrieb am Do., 8. Sept. 2022, 15:29:

I'm trying to play a local file resource, with a uri like:

file:///var/mobile/Containers/Data/Application/C52537C1-6DDE-438B-AFC4-243C526143D0/Documents/a65c53f77de85cce59b536502b5c3b99

I'm getting error:

RmxAudioPlayer.onStatus: Error(5) [a65c53f77de85cce59b536502b5c3b99]: {"code":3,"message":"Error playing audio track: This media format is not supported."}

I suspect that this is because the Content Type is incorrect or not specified. My local file is an audio/mpeg content type.

How can I set this in the plugin or successfully play this local file?

— Reply to this email directly, view it on GitHub https://github.com/phiamo/capacitor-plugin-playlist/issues/59, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABSTO4KT32RZVZDQVXXQXLV5HS23ANCNFSM6AAAAAAQHYAEUM . You are receiving this because you are subscribed to this thread.Message ID: @.***>

timstoute commented 2 years ago

ok, thanks, I'm testing various patterns, still with no success i'll update this if I find a solution would appreciate any insights or examples

timstoute commented 2 years ago

I got this working; it wasn't a content type issue - seems more like a path issue and or a file type issue (mpeg vs mp3).

I am downloading and saving an mp3 file from Google Cloud Storage with a (signed) download url that looks like: https://storage.googleapis.com/***.appspot.com/97bf4fe43288be145c0301dd3d8d33f7.mp3?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=***%40appspot.gserviceaccount.com%2F20220916%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20220916T110208Z&X-Goog-Expires=518401&X-Goog-SignedHeaders=host&X-Goog-Signature=9cbbf361b204f7b9dc507afff90e902df722e9447f74ea61c7b21f0a99ece3843d7623422be2d5497041d0c0a79d5bafdd25b4c075ebd97c8c1317d8857f8894e1a953ad670aaaaa1fdf812689f2a73c512d5a610ae625b0469cfb9b20a6d7d67b9174856f6fa570dbd11b1285ee614ab0c35c543258eac95b53dfb2dac9a063f36866137b8a27b44cfb15149412743a41b4037508d28112df2c8fc653cbd69dca9d29ec0c979c99051022f830d3248b2ddca4c70fa2549c4cc1818b7b5207feccd6c56d3d960712a163c09cff81f4e5e5b1c0767e8411ed70c3db7b546ca3344db50c32075b6036743b51d1732f52287c7b40767adb02e84d588826c3c185b9

using @capacitor-community/http and @capacitor/filesystem I download and save the file locally. This results with a local path like this: file:///var/mobile/Containers/Data/Application/EA05C620-0705-4C3B-B0F5-027EC7295BEC/Documents/97bf4fe43288be145c0301dd3d8d33f7.mp3

and that is what I pass into the capacitor-plugin-playlist via the assetUrl field

phiamo commented 2 years ago

Hi @timstoute thanks a lot, do you think we can document your issue, and the solution ?

timstoute commented 2 years ago

Ok, here are more details for iOS, Angular, Ionic; is this helpful?


  import { Http, HttpDownloadFileResult } from '@capacitor-community/http';
  import { Directory, Filesystem } from '@capacitor/filesystem';

...

  const options = {
    url: item.downloadMp3Url,
    filePath: item.itemId + ".mp3",
    fileDirectory: Directory.Documents,
    // Optional
    method: 'GET',
  };

  try {
    const response: HttpDownloadFileResult = await Http.downloadFile(options);
    if (response.path) {
      console.log("downloaded file result = ", response.path);

      const mp3Uri = await Filesystem.getUri({
        path: item.itemId + ".mp3",
        directory: Directory.Documents,
      });

      // the downloaded file will now have a local file path = mp3Uri.uri

    } else {
      console.log("response.path doesn't exist, response = ", response)
    }

  } catch (err) {
    console.log("error in http download: ", err);
  }