fregante / iphone-inline-video

📱 Make videos playable inline on the iPhone (prevents automatic fullscreen)
https://npm.im/iphone-inline-video
MIT License
2.06k stars 298 forks source link

Only dispatch playback events if audio is playable #46

Closed ivanschwarz closed 8 years ago

ivanschwarz commented 8 years ago

Currently play event is dispatched also in cases, where the audio element is not user-initiated. I propose proxying playback events from the audio element to the video element.

fregante commented 8 years ago

I'm not sure I understand what the issue was, what do you mean by "the audio element is not user-initiated"?

ivanschwarz commented 8 years ago

On iPhone play event is not dispatched until user interaction occurs (see demo). With the current version, the play function always dispatches a play event. Even if the video is not yet playable.

fregante commented 8 years ago

The spec defines the play event to be fired when .play() is called on a paused media. iphone-inline-video already works like that.

I think you're referring to the playing event, which should fire when the playhead actually starts moving. That is indeed broken but I'd need to make it work properly also when there's no audio.

I hope I'm understanding you correctly.

ivanschwarz commented 8 years ago

The spec defines the play event to be fired when .play() is called and the media was paused. iphone-inline-video already works like that.

iPhone doesn't behave that way, please check the demo on iPhone. Even though you follow the spec correctly, iPhone doesn't.

fregante commented 8 years ago

I did and 9.3 does follow the spec:

live

What version are you testing on?

ivanschwarz commented 8 years ago

Well, but look at the last line of the javascript source code. On desktop you immediately see a play event, whereas on iPhone, line 6 doesn't result in a play event. iPhone doesn't dispatch a play event until user interacts. With iphone-inline-video the media element wont play, but it will still dispatch a play event.

fregante commented 8 years ago

Ohhhh I see what you mean, .play() fires the event but it will never actually play unless the user touches it.

Yes. I'll look into this when I can.

Ideally I'd fix it by finding out whether it can play, because even with your PR the update code still runs at every frame waiting for the audio to play. This probably uncovers some other unwanted behavior too.

fregante commented 8 years ago

I merged this manually and it's now in 1.9.0

Thank you!