Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live streams (over http, like web radio) don't play on iOS #324

Open
3 tasks done
bikubi opened this issue Dec 15, 2021 · 7 comments
Open
3 tasks done

Live streams (over http, like web radio) don't play on iOS #324

bikubi opened this issue Dec 15, 2021 · 7 comments

Comments

@bikubi
Copy link

bikubi commented Dec 15, 2021

Bug Report

Problem

What is expected to happen?

new Media('http://example.com/finite.mp3'); plays a sound from the internet,
new Media('http://example.com/infinite-radio-live.mp3'); should play a live streaming sound.

What does actually happen?

I see a status update to 2 (MEDIA_RUNNING), but there is no sound.

Information

I've tried different radio stations (servers), protocols (http(s)) and formats (mp3, aac) to no avail.

Command or Code

I have made a Minimal Reproduction Repo, originally in the probably unrelated issue #242 (OP mentions Android):
https://github.com/bikubi/cordova-plugin-media-mwe

I have since found the issue and a possible fix: player.automaticallyWaitsToMinimizeStalling has to be true -- which makes sense with live streaming ("let it buffer").
I have implemented it as a proof of concept: bikubi@591a777
...and have my MRR use it in branch hotfix.
I'd fashion a PR, but am not sure where to put my fix (and how, this was my first line of ObjectiveC (?)), especially how to apply it only when the url is a live stream. There's no way to tell by the URL, so I guess it would have to be an extra parameter.

Environment, Platform, Device

  • iOS 15.1 on iPad
  • 12.3.1 on an iPhone SE
  • 15.0 in an iPhone 13 emulator.

Version information

cordova 10.0.0
cordova-ios 6.2.0
cordova-plugin-file 6.0.2
cordova-plugin-whitelist 1.3.5
XCode 13.1 on macOS 11.6

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
@bikubi
Copy link
Author

bikubi commented Dec 16, 2021

not sure where to put my fix

Maybe as option for play() akin to playAudioWhenScreenIsLocked.
Would fit nicely under iOS quirks, too...

@ShaunBrassell
Copy link

Thanks, solved my issue

@bikubi
Copy link
Author

bikubi commented Aug 30, 2022

I have noticed that my fix above has problems with AirPlay:

  • play the stream, connect to an AirPlay receiver — receiver plays the stream as expected
  • but, when you enable AirPlay and "pre-connect" to a receiver, and THEN star playing, there is no sound (MEDIA_RUNNING but no progress)

With a vaguely related StackOverflow answer I was able to guess a fix:

[avPlayer setAllowsExternalPlayback:NO];

see commit a8527f5.

No idea about what this actually does, or if it might have any unintended side-effects.

I've also updated the Minimal Repro repo linked above.

@bikubi
Copy link
Author

bikubi commented Aug 31, 2022

randomly found out that this was introduced with #149, so it probably broke somewhere between iOS 11 and 12

@ddurham2
Copy link

ddurham2 commented Dec 17, 2022

v6.1.0

I too am getting no playback on iOS when streaming from the network a live stream. This stream I don't believe gives a content length and that may be part of the problem given what the docs say, but I'm not positive.

For now, I'm having to patch the code thusly:

--- node_modules/cordova-plugin-media/src/ios/CDVSound.m.orig   2022-12-16 19:32:41.000000000 -0600
+++ node_modules/cordova-plugin-media/src/ios/CDVSound.m        2022-12-16 19:32:28.000000000 -0600
@@ -272,11 +272,7 @@
             // Pass the AVPlayerItem to a new player
             avPlayer = [[AVPlayer alloc] initWithPlayerItem:playerItem];

-            // Avoid excessive buffering so streaming media can play instantly on iOS
-            // Removes preplay delay on ios 10+, makes consistent with ios9 behaviour
-            if ([NSProcessInfo.processInfo isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){10,0,0}]) {
-                avPlayer.automaticallyWaitsToMinimizeStalling = NO;
-            }
+            avPlayer.automaticallyWaitsToMinimizeStalling = YES;
         }

         self.currMediaId = mediaId;

... basically reverting this change.

Also, regarding the original reason for the change, it doesn't wait 8-10 seconds in my case.. My guess is that the original complaint was hitting a source that was throttled to just the needed bandwidth, but didn't allow an initial burst of bandwidth to get the process started and buffers filled up.

I'm thinking it needs to be an caller-controlled option, or more careful thought needs to be given to that change.

@matias-tecnosoul
Copy link

matias-tecnosoul commented Feb 24, 2023

This seems to still be happening with Cordova 11.1.0 and ios 6.2.0.

I've also tried with the html audio tag but got same problem.
Whenever I insert any live audio in my index.html the app freezes when starting.

I tried with iframes and got 1 js player working but not others.

Any hints to make an icecast stream play in ios?

@pinguluk
Copy link
Contributor

pinguluk commented Jun 6, 2024

This seems to still be happening with Cordova 11.1.0 and ios 6.2.0.

I've also tried with the html audio tag but got same problem. Whenever I insert any live audio in my index.html the app freezes when starting.

I tried with iframes and got 1 js player working but not others.

Any hints to make an icecast stream play in ios?

#256

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants