apache / cordova-plugin-media

Apache Cordova Media Plugin
https://cordova.apache.org/
Apache License 2.0
388 stars 767 forks source link

Ionic Capacitor iOs: Media create INVALID (https url) #330

Open anonymze opened 2 years ago

anonymze commented 2 years ago

Hello and thank you for your awesome work !

Bug Report

Problem

On iOs, the song is not playing and i got an error on the Xcode's console. I create my media with an https URL where i get my audio file (it can be a .mp3 or a .wav file).

What is expected to happen?

It should be playing the song, it works like a charm on Android.

What does actually happen?

I got this error on the Xcode's console (i suppose it is related to why it's not working):

To Native Cordova ->  Media release Media1406211762 ["options": [31e0d8f6-8bc9-bef4-c05c-029d1002b2f9]]
To Native Cordova ->  Media create INVALID ["options": [ed2b3395-21d6-381f-0caf-070428409a48, http://viny.openstudio-lab.com/post/file/d45b1000-289f-4f5e-9a3d-c888332d78cd]]
2022-02-02 10:04:29.064381+0100 App[35121:1018948] Will use resource 'http://viny.openstudio-lab.com/post/file/d45b1000-289f-4f5e-9a3d-c888332d78cd' from the Internet.
⚡️  [log] - http://viny.openstudio-lab.com/post/file/d45b1000-289f-4f5e-9a3d-c888332d78cd
To Native Cordova ->  Media startPlayingAudio INVALID ["options": [ed2b3395-21d6-381f-0caf-070428409a48, http://viny.openstudio-lab.com/post/file/d45b1000-289f-4f5e-9a3d-c888332d78cd, {
    playAudioWhenScreenIsLocked = 0;
}]]

2022-02-02 10:24:58.431168+0100 App[50328:1066952] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x600002f3dc60> F8BB1C28-BAE8-11D6-9C31-00039315CD46
2022-02-02 10:24:58.840417+0100 App[50328:1066959] [] nw_protocol_get_quic_image_block_invoke dlopen libquic failed
2022-02-02 10:24:58.859793+0100 App[50328:1066952] Playing audio sample 'http://viny.openstudio-lab.com/post/file/d45b1000-289f-4f5e-9a3d-c888332d78cd'
2022-02-02 10:24:58.943981+0100 App[50328:1066952] Duration is infifnite (TYPO !), setting it to -1
2022-02-02 10:24:58.944771+0100 App[50328:1066952] Playing stream with AVPlayer & default rate

Command or Code

There is my url where i get the audio file: https://api.viny.club/post/file/47678658-88ab-4f6e-97f1-31d65b4cf152

My code:

import { Media, MediaObject } from '@ionic-native/media/ngx';

export class MediaService {
  file: MediaObject;

 constructor(private media: Media, ...){}

  initMedia(fileId) {
    this.file = this.media.create(fileUrl);

    this.file.onStatusUpdate.subscribe((status) => {
       ...
      // status 2 is detected but NO SOUND is played
      // status 3 detected too, status 1 and 4 not detected
    });

    this.playMedia();
  }

  playMedia(): void {
    if (this.file instanceof MediaObject) { // not necessary but for safety
      this.file.play({ playAudioWhenScreenIsLocked: false }); // i tried without the ios option too
    }
  }
}

Environment, Platform, Device

Ionic + Capacitor / iOs / emulator iPhone on Xcode (tried on iPhone 11 and 12).

Version information

"@ionic-native/media": "^5.36.0", // tried with the last version of awesome cordova same result "cordova-plugin-media": "^5.0.4" "@capacitor/core": "^3.2.5" "@capacitor/ios": "3.2.5" "@ionic/angular": "^5.5.2", dev: "@angular/cli": "12.1.4" "@capacitor/cli": "^3.3.2",

Checklist

anonymze commented 2 years ago

The issue seems related to this one: #324 But the fix didn't work for me. I added this in CDVSound.m (line 398):

 if (audioFile.rate != nil){
                       float customRate = [audioFile.rate floatValue];
                       NSLog(@"Playing stream with AVPlayer & custom rate");
                       [avPlayer setRate:customRate];
 } else {
                      NSLog(@"Playing stream with AVPlayer & default rate");
                      avPlayer.automaticallyWaitsToMinimizeStalling = true; // i added this line !
                      [avPlayer play];
 }
bikubi commented 2 years ago

There is my url where i get the audio file: http://viny.openstudio-lab.com/post/file/d45b1000-289f-4f5e-9a3d-c888332d78cd

Please note that this is not an https URL. Might matter, might not.

anonymze commented 2 years ago

There is my url where i get the audio file: http://viny.openstudio-lab.com/post/file/d45b1000-289f-4f5e-9a3d-c888332d78cd

Please note that this is not an https URL. Might matter, might not.

Hello,

Same result with a https URL.

bikubi commented 2 years ago

I assume you switch BasicAuth on/off for testing, or use an IP-based filter? I only get 401 for both http and https.

anonymze commented 2 years ago

Hello,

Yes sorry, i completely forgot. There is an accessible URL: https://api.viny.club/post/file/47678658-88ab-4f6e-97f1-31d65b4cf152