I’ve noticed that pressing Pause/Play media keys can control an audio player within Chrome, and I know that on mobile devices, you can even seek through whatever’s playing out of Safari / Chrome etc
Is there a way to programmatically seek a tab/browser’s currently playing audio? I’m wondering if there’s a w3c standard for this media key functionality and/or if theres an “extension” api to pause/play/seek or get info on what’s playing, because it seems to be exposed on mobile devices
I guess you are looking for the Media Session Standard.
Related
I'm recording audio using getUserMedia, then allowing the user to click a button to listen to either the recording or another buffer. This has all worked fine for a year, so I don't think I'm violating any of the rules that cause AudioContext to be suspended. And, anyway, I'm testing the AudioContext to make sure it isn't suspended in my button handler.
This has all been working fine on all modern systems with many browsers. However, this is not playing the audio in Safari 13 in iOS. It will return from the promises as if it were playing audio, but nothing sounds until I call getUserMedia again.
As an experiment, I put the following line on the top of my button handler:
navigator.mediaDevices.getUserMedia({
audio: {
echoCancellation: {ideal: false},
}
});
And it works!
But, why? I'm not comfortable with that solution because I'm not sure why the browser wants that. It doesn't make sense to me that I'd have to request the microphone to play any sound.
The only clue I have is that once I do the getUserMedia I keep the recording open on Safari (I do that because Safari has a time out - when I request the mic, it pops up a dialog to the user to allow the mic. Sometimes it might take the user 90 seconds to get around to pressing "record", and if I don't leave the mic open it pops up the dialog again.)
Anyone have any idea what is going on? And, I haven't been able to find any technical write up of Safari and audio. Is there anything beyond the standard MDN?
IOS13 also broke one of our applications. It's been working fine for years. No errors are thrown and we are not violating any rules. Here is the link to my post:
Has IOS13 broken <audio> tags used as audio buffers connected to the audio context?
Even though it is a different use of the api, I believe it is related. Apple clearly broke something on this new release.
This was confirmed to be a bug in Safari 13 and was fixed in a maintenance release. We haven't heard any more reports from the field so I guess it auto updated for everyone.
How can I detect whether the actual HTML5 player is being used, or if a 3rd party player is hi-jacking the video outside of HTML5?
iPhone doesn't use the HTML5 video player (thanks Apple) but rather uses its own player full-screen. This means any apps, regardless of responsive design, don't work if they expect an interface to be involved with the video.
So I need to know this in order to either make my app work differently with devices that do something similar to iPhone, or at least fail gracefully.
As I told in you in my comment, it seems that is not possible.
So I am afraid that you will need to go for agent sniffing. Check this post to see how to identify an iOS device.
Is there any way of preventing a device to "sleep" when on the website?
(Desirable because of playing YouTube videos from a device on a website)
Look at this post
Prevent iOS mobile safari from going idle / auto-locking / sleeping?
It seems like it is currently not possible to implement. Youtube has this feature because they are using quicktime that keeps the device awake.
I have read that autoplay was not possible, or not advised on both iOS and Android (more on that here: no autoplay in iframe HTML5 player on mobile (Android Chrome and Firefox)?). But I was wondering if there was a way that would allow to replicate the same behavior, that is the video playing soon as the page is loaded.
I have tried preloading the video, and playing it once the DOM is loaded, I tried forcing a play soon as the video can be played, none of that work, it always result in the user having to tap the video to play it.
Can anyone help?
NB: I'm working with plain old JavaScript, no jQuery.
No, there is no way on iOS/Safari (or iBooks).
Videos load only in the context of an event handler reacting to user action such as a touch.
You're out of luck.
This has been documented extensively in any number of questions right here on SO, and is clearly documented by Apple.
I've been evaluating HTML5 audio on iOS 4 and have been trying to understand its limitations. From what I can tell...
It is possible to play audio in the background
It is not possible to fire JavaScript events in the background upon track completion
It is possible to fire JavaScript events while the screen is off, but Safari must be in the foreground (before turning the screen off)
My goal for this current project is to create a dynamic playlist that will continue to fire events and move to the next track even while Safari is not in the foreground. Is this possible with the current way HTML5 audio works on iOS?
I am curious about how the chaining of JavaScript events works on iOS if anyone has additional information. It seems that you are allowed to queue back to back sounds, but it must happen shortly after a "human" function happens (for example, tapping an element). Anything else that tries to queue a sound outside of this human function is denied the ability to play.
Also...
Is it even possible to have events that fire to move a real iOS application to the next track? It seems as if the application is only allowed to finish its current audio stream and then it goes into an idle state. Just trying to figure out all the angles here!
This is quite an old question, so I'm not sure if you've found an answer already or not.
One thing I know is that an audio clip cannot be played via JavaScript on mobile Safari.
Autoplay audio files on an iPad with HTML5
The only way to make audio play, is through a click event. This wasn't the case on 3.x, but on 4.x it is. This is because Apple doesn't want the webapp to download audio on a 3g connection programmatically, so they force the user to initiate it.
I would think that if all of the tracks were started downloading (cached), then it may be possible. I would try forcing the user to start one track, and at the same time call .load() on all of the other tracks (in the same click handler). This will force the iOS device to start downloading the audio tracks, and you may be able to play the next track (not sure though).