[Webkit-unassigned] [Bug 252465] In PWA, HTML Video Element may be unable to play stream from 'getUserMedia()'

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Wed Jun 28 01:52:11 PDT 2023


https://bugs.webkit.org/show_bug.cgi?id=252465

--- Comment #40 from Chris <chrissyg at protonmail.com> ---
(In reply to Andre from comment #39)
> (In reply to Chris from comment #35)
> > (In reply to rooke from comment #34)
> > > Just to add to the information available, and provide a detection method,
> > > you can subscribe to the HTMLMediaElement's events (e.g. <video muted="true"
> > > />). In a normal situation, the events follow this order:
> > > 
> > > play 
> > > waiting 
> > > loadstart 
> > > progress 
> > > suspend 
> > > durationchange 
> > > loadedmetadata 
> > > loadeddata 
> > > canplay 
> > > playing 
> > > canplaythrough
> > > timeupdate (repeatedly for every frame)
> > > 
> > > When the PWA camera issue rears its head, the events are cut off at
> > > 'suspend', i.e.:
> > > 
> > > play 
> > > waiting 
> > > loadstart 
> > > progress 
> > > suspend 
> > > <then nothing>
> > > 
> > > This is the method to detect when you're in that situation. Just timeout on
> > > any of the missing 'expected' events, e.g. canplay:
> > > 
> > > let timeoutId: NodeJS.Timeout;
> > > 
> > > // set timeout of 3 seconds to wait for oncanplay
> > > timeoutId = setTimeout(() => {
> > >   // The video didn't get to 'canplay'
> > > }, yourPreferredTimeoutInMillis);
> > > 
> > > videoElement.oncanplay = () => {
> > >   // clear the timeout because oncanplay was called
> > >   clearTimeout(timeoutId);
> > > };
> > 
> > 
> > 
> > This is really helpful, thank you
> > 
> > I’d been doing something similar already with a chained function call that
> > executes after a timer is set to say the camera couldn’t be loaded. If the
> > function succeeds and it progresses past “suspend” then the timer is cleared
> > and the camera is displayed.
> > 
> > Being able to detect the problem was half the battle but obviously having an
> > actual fix for this is the dream! In the meantime a work around to detect
> > the issue and then get the camera working again without user input would be
> > great, too…
> 
> Still not working on 16.5.1 :(
> 
> Can you show an example of your code how you fixed it with a workaround? I
> tried a lot but nothing worked for me.

Hi Andre- there is no fix... currently the only way to get the camera back is to restart the iPad/iPhone or wait (for quite a long time, apparently) and close/re-open the home screen app

If you want to detect when the camera can't be loaded you can do something like this in JS:

======================
  var cameraFailTimer
  cameraStarting = true
  const constraints = {
    audio: false,
    video: { 
      facingMode: 'user'
    }
  }
  navigator.mediaDevices.getUserMedia(constraints)
    .then((mediaStream) => {
      cameraView.srcObject = mediaStream
      clearTimeout(cameraFailTimer)
      cameraFailTimer = setTimeout(function(){
        // Camera isn't working - do something on screen
        cameraStarting = false

      }, 12000)
      cameraView.onloadedmetadata = () => {
        cameraView.play().then(function() {
          // Camera is working - continue as normal
          clearTimeout(cameraFailTimer)
          cameraStarting = false
          callback(true)
        })
      }
    })
    .catch((err) => {
      // Camera isn't working - do something on screen
      cameraStarting = false
      callback(false)
    })
======================

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20230628/8ad65dd4/attachment-0001.htm>


More information about the webkit-unassigned mailing list