snapweb icon indicating copy to clipboard operation
snapweb copied to clipboard

iOS not playing

Open sys-b opened this issue 3 years ago • 42 comments

Under iOS the controls are working fine. Just like the desktop. But the client is not playing. It is displayed linke on the desktop, but no audio is played. Tried in Chrome, Safari, Firefox and even Opera. The iPad-chrome-console output after while pressing play: IMG_0030

sys-b avatar Oct 09 '20 22:10 sys-b

What iOS version is your iPad running on? Have you tried playing audio on an iPhone? Here they say that on iOS 10.1.1 the web audio API is not working: https://developer.apple.com/forums/thread/48815

This was fixed in the second build of iOS 10.1.1. iPad now plays Web Audio API again, but didn't from 9.3.2 to the first build of 10.1.1. Thanks.

badaix avatar Oct 10 '20 17:10 badaix

It is an iPad Pro. Running iOS 14.0.1. Same as an iPhone 11 Pro Max. Also Not Working. On the current iMac it only works in chrome also, Not in safari. Maybe an webkit Issue.?

sys-b avatar Oct 10 '20 17:10 sys-b

Yep, smells like an compatibility issue with webkit. I don't own any iDevices to fix this, so I've labelled this with "help wanted".

badaix avatar Oct 10 '20 18:10 badaix

@sys-b @FredVDB Can you try the develop branch? Or extract this file snapcontrol.js.zip and copy it to your doc_root (default should be /usr/share/snapserver/snapweb/)

badaix avatar Oct 18 '20 20:10 badaix

Still no audio with the modified snapcontrol.js. Is there some way to get logging info ?

FredVDB avatar Oct 19 '20 07:10 FredVDB

Yes, this should be possible: https://stackoverflow.com/questions/4478271/remote-console-log-on-ios-devices

The modified snapcontrol.js introduced an explicit event listener for the play button click event, as suggested on stackoverflow. Before it was a link to a java script function. I think without having an iOS device, I'm out for now :(

Did you restart the snapserver after copying the file? The server doesn't cache (refreshing the browser should be enough), but who knows.

badaix avatar Oct 19 '20 08:10 badaix

Hi. I just pulled the development branch, make, replaced the folder, restart service.

It seems to behave like before. In Chrome on iPadOS 14: IMG_0031

Also interesting is, that it isn't working in Safari on the recent iMac and recent OS: Bildschirmfoto 2020-10-19 um 12 55 14

Hopefully this will help.

sys-b avatar Oct 19 '20 10:10 sys-b

Can you please try again the develop branch or the attached snapstream.js.zip? Snapweb is now falling back to webkitAudioContext if there is no AudioContext

badaix avatar Oct 19 '20 13:10 badaix

No sound but different errors. On both devices: Bildschirmfoto 2020-10-19 um 19 11 42 IMG_0032

In Chrome on the iMac the sound still works. But the Failed to get Chunk error appears 3 times. I didn't saw that before, I think... Bildschirmfoto 2020-10-19 um 19 20 09

sys-b avatar Oct 19 '20 17:10 sys-b

The chrome log looks as expected, the audio player tries to fill the buffer before having received the first audio chunk. The TypeError should be fixed now, please try again. Mühsam nährt sich das Eichhörnchen... snapstream.js.zip

badaix avatar Oct 19 '20 19:10 badaix

I am happy that we are going to figure it out. But still sound. This time same log results on Safari MacOS and Chrome iPad: Bildschirmfoto 2020-10-19 um 21 32 25

IMG_0033

Wer im Glashaus sitzt, fällt selbst hinein.

sys-b avatar Oct 19 '20 19:10 sys-b

So the error message disappeared, the undefined Base latency is used to calculate the play-out time. The latency is now set to 0 if undefined: snapstream.js.zip Please also make sure that you're not muted: https://stackoverflow.com/questions/21413396/simple-oscillator-but-no-sound-with-web-audio-api-on-ios

$10 says your mute switch is on. For whatever reason, Safari won't play sound when the mute switch is engaged, but Chrome will. Other than that, Chrome uses the same engine as Safari to render your page (minus the Nitro JS optimizations), so there's no other reason that your code should work in one but not the other. I just tried it via JSBin, and both worked for me when the mute switch was off. –

badaix avatar Oct 19 '20 20:10 badaix

The iPad doesn't have a mute switch. Other websites like YouTube work. On the iPhone with mute off also no sound. I am not sure if it is clear, that the last message on the console is the last one. On a working Browser there are coming a lot with age: and others messages.

IMG_0034

Bildschirmfoto 2020-10-19 um 22 19 05

I had once problems with video html5 elements. They had to be muted if not, the element wasn't playing automatically. I'm starting to think this is more a communication thing than an output thing. Is it possible to use a dummy output maybe ? Anyway I am not into any JS or TS at all.

Gute Nacht.

sys-b avatar Oct 19 '20 20:10 sys-b

Snapweb is using a triple audio buffer. When a buffer finished playing, it should fire an ended event, fetch new audio data and get queued for the next play back. Here the ended event seems not to get fired and thus the whole logging stops. One more attempt with a different ended callback handling: snapstream.js.zip

badaix avatar Oct 19 '20 21:10 badaix

I have tested it, with same result and (almost) same log. :(

sys-b avatar Oct 20 '20 15:10 sys-b

When one of my programmers is back from holidays I will give him the task to fix this. He is really fit in TypeScript.

sys-b avatar Oct 21 '20 21:10 sys-b

Sounds good :) If he needs any support, don't hesitate to contact me.

badaix avatar Oct 28 '20 12:10 badaix

I started poking at this a few days ago to see if I could get anywhere. From what I can tell the context is suspended and thats why the ended callback isn't working. We obviously click play to start the audio session so maybe creating the context is just buried deep enough in other functions to make Safari suspend it but I will continue to investigate.

Related: https://stackoverflow.com/questions/46249361/cant-get-web-audio-api-to-work-with-ios-11-safari

inickt avatar Jan 11 '21 23:01 inickt

@inickt @FredVDB @sys-b I could reproduce the issue that onended is not called and no audio is played in Epiphany, which is based on WebKitGTK 2.30.3. I got it working by creating the AudioContext in the constructor of SnapStream, instead of in onMessage. The difference is that the constructor is directly called from in the onclick event, while onMessage is called upon reception of some message over a websocket, i.e. from a different context/thread. I've pushed the change into the webkit branch. Now I'm curious if this will also work in Safari/iOS. Can anyone of you test this?

badaix avatar Jan 12 '21 21:01 badaix

It works (kinda)! Plays fine on my iPhone on iOS 13.5. Safari on macOS Big Sur and my iPad on iPadOS 14.2 sounds pitch shifted up and stutters, but its something! Since its fine on 13 I'm guessing Safari version 14 broke something. I can investigate and send logs if you want.

For my iPhone and iPad I had to make sure it wasn't muted, this seems to be a common issue people run into with how they set up the audio session. Not sure how the AudioContext interacts with HTML5 audio tags (which iOS will support at the system level recognized as music instead of just noise) but this is likely something that can be fixed.

Someone made this package to fix this but here might be some pointers to implementing it manually: https://github.com/goldfire/howler.js/issues/1220 https://stackoverflow.com/questions/21122418/ios-webaudio-only-works-on-headphones/46839941#46839941

inickt avatar Jan 12 '21 22:01 inickt

Snapweb uses BaseAudioContext.currentTime to synchronize the playback. Maybe in Safari 14 the time precision is reduced, a log would help here.

badaix avatar Jan 13 '21 08:01 badaix

I have an iPad and would like to help debug this. Let me know what I can do.

jtrees avatar Jan 31 '21 18:01 jtrees

I can confirm that the latest commit from master (520b9a38588f0c8788c1be258056ae1849149b4e) works with Safari and Firefox (guess it's all WebKit under the hood).

Unfortunately the sound stops (with a nice fade out transition) whenever the app loses focus or the screen of the device is turned off. But I guess that's an out-of-scope issue for this project.

jtrees avatar Jan 31 '21 19:01 jtrees

I can confirm that the latest commit from master (520b9a3) works with Safari and Firefox (guess it's all WebKit under the hood).

Unfortunately the sound stops (with a nice fade out transition) whenever the app loses focus or the screen of the device is turned off. But I guess that's an out-of-scope issue for this project.

thats actually something that prevents the app from actually being useful on IOS. you can still use it as a remote control but listening to music on the phone is not really working for me like that (who keeps the display on all the time?). what would also be nice: having controls in controlcenter just like in other mediaplaying-apps.

cheers bendsch

bendschs avatar May 07 '21 22:05 bendschs

@bendschs Just in case you don't know about it, there is a native iOS app that is able to stream audio in the background: https://github.com/stijnvdb88/Snap.Net

jtrees avatar May 09 '21 12:05 jtrees

thanx for the hint. i tried the app but it‘s functions are really reduced. you can not skip songs there, neither play or stop them. it‘s basically just for turning on the phones (or other) speakers, so it‘s not really an alternative to iris (nor is it a very valuable addition). porting iris to ios as a real app might be a bigger project but what about adjusting the pwa so you can background it on ios? from my understanding playing sound is something a pwa can without restrictions so that should be possible, right?

cheers bendsch

bendschs avatar May 20 '21 17:05 bendschs

just tested one more time with mopidy-iris and with native webinterface of snapserver: audio oputput of snapweb seems to be broken for ios right now (tried various browsers but that probably does not even make a difference beacause in the end they are all "webkit"). as i noticed as well: only the latest ios versions 14.5 and 14.6 are affected. i have an older iphone which is still on 14.2, on that it works as expected. on my actual (daily) phone i stopped working (i think) with the update to version 14.5.

cheers bendsch

bendschs avatar May 31 '21 22:05 bendschs

I can confirm that the latest commit from master (520b9a3) works with Safari and Firefox (guess it's all WebKit under the hood).

Unfortunately the sound stops (with a nice fade out transition) whenever the app loses focus or the screen of the device is turned off. But I guess that's an out-of-scope issue for this project.

is this working for you guys? i am on IOS 14.7.1 and tried with the dev-branches and the modified snapstream.js but it‘s not working, when i hit the play button i get a message with the content "error" (and nothing else).

bendschs avatar Sep 11 '21 12:09 bendschs

sad that nobody seems to be able or willing to solve this 😢

bendschs avatar Oct 05 '21 21:10 bendschs

why is this closed, it‘s definitely not working on safari (nor on macos, nor on ios). i am willing to provide logs if needed.

bendschs avatar Feb 19 '22 14:02 bendschs