HTML5视频中的事件监听器不工作吗?

时间:2022-08-26 19:00:53

I've got this in the <head>:

我在:

<script>
      function log(event){
     var Url = "./log.php?session=<?php echo session_id(); ?>&event=" + event;

        xmlHttp = new XMLHttpRequest(); 
        xmlHttp.open( "GET", Url, true );
        xmlHttp.send( null );

    }
</script> 

And this in the <body>:

在:

<video id="video" src="./video/LarryVideo.mp4" 
  controls="controls" 
  poster="./img/video_poster.jpg"
  onabort="log('onabort');"
  oncanplay="log('oncanplay');"
  oncanplaythrough="log('oncanplaythrough');"
  ondurationchange="log('ondurationchange');"
  onemptied="log('onemptied');"
  onended="log('onended');"
  onerror="log('onerror');"
  onloadeddata="log('onloadeddata');"
  onloadedmetadata="log('onloadedmetadata');"
  onloadstart="log('onloadstart');"
  onpause="log('onpause');"
  onplay="log('onplay');"
  onplaying="log('onplaying');"
  onprogress="log('onprogress');"
  onratechange="log('onratechange');"
  onreadystatechange="log('onreadystatechange');"
  onseeked="log('onseeked');"
  onseeking="log('onseeking');"
  onstalled="log('onstalled');"
  onsuspend="log('onsuspend');"
  ontimeupdate="log('ontimeupdate');"
  onvolumechange="log('onvolumechange');"
  onwaiting="log('onwaiting');">
    <script>
        QT_WriteOBJECT('./video/LarryVideo.mp4',
            '380px', '285px',           // width & height
            '',                         // required version of the ActiveX control, we're OK with the default value
            'scale', 'tofit',           // scale to fit element size exactly so resizing works
            'emb#id', 'video_embed',    // ID for embed tag only
            'obj#id', 'video_obj');     // ID for object tag only
    </script> 
</video>

My normal Safari creates nice log-file entries as expected. Mobile Safari from iPad however doesn't do anything at all.

我的正常的Safari会按照预期创建良好的日志文件条目。然而iPad的移动Safari却什么也没做。

What could be wrong with this?

这有什么问题呢?

Thanks!

谢谢!

1 个解决方案

#1


36  

I have not been able to get a hold of readystate on an ipad either but you can get other events that more-or-less let you infer the readystate.

我还没能在ipad上获得readystate,但你可以得到其他的事件,或多或少让你推断出readystate。

var audio = new Audio("someSource.mp3");
    audio.play(); 
 /* you may need to use .load() depending on how the event was initiated */
    audio.addEventListener("canplay", handleCanPlay, false);
    audio.addEventListener("durationchange", handleDurationChange, false);

But lets be clear, the problem is Apple pretty much telling the whole damn world they're using the internet wrong. Granted, everyone hates sites that start playing music the second they load but then Apple goes nuts and kills ANY/ALL buffering of audio/video that isn't explicitly initiated by a user gesture because Apple, apparently, thinks their users are too retarded to hit "back" if a site bothers them; fanboys agree too. This basically leaves the rest of us to hack the shit out of our applications if we dare try and manage any kind of sound effects. I know this isn't the place to rant...but i'll be damned if building ANY soft of interesting/interactive experience in HTML5 on the iPad isn't one facepalm after another...be it the 5mb cache limit that simply crashes the browser if a page has *too many (according to Apple) images or the difficulty to preload any sort of media to enhance UI - seriously, outside of wordpress blogs and rss readers, mobile Safari's implementation of HTML5 is pretty worthless. And so the dream of HTML5 "build once, play anywhere" value proposition is dead and we go back to deving native apps...at least this gives us good job security /rant

但我们要清楚的是,问题是苹果公司对整个该死的世界都说错了。当然,每个人都讨厌那些开始播放音乐的网站,但后来苹果疯了,并杀死了所有的音频/视频,而这些都不是由用户的手势直接引发的,因为显然,苹果认为他们的用户太迟钝了,如果一个网站让他们烦恼的话,他们就会被“退回”。粉丝也同意。如果我们敢于尝试和管理任何一种声音效果,这基本上就会让我们剩下的人来破解我们的应用程序。我知道这不是发泄的地方…但是,如果在iPad上构建任何一种有趣的/交互式的HTML5体验,那么我就不会被指责了。如果一个页面有太多(根据苹果的)图片或难以预加载任何类型的媒体来增强用户界面,那么它就是5mb的缓存限制(根据苹果的图片),在wordpress博客和rss阅读器之外,移动Safari的HTML5的实现是毫无价值的。因此,HTML5的梦想“构建一次,发挥任何地方”的价值主张已经消亡,我们又回到了原始的应用程序……至少这给了我们很好的工作保障。

#1


36  

I have not been able to get a hold of readystate on an ipad either but you can get other events that more-or-less let you infer the readystate.

我还没能在ipad上获得readystate,但你可以得到其他的事件,或多或少让你推断出readystate。

var audio = new Audio("someSource.mp3");
    audio.play(); 
 /* you may need to use .load() depending on how the event was initiated */
    audio.addEventListener("canplay", handleCanPlay, false);
    audio.addEventListener("durationchange", handleDurationChange, false);

But lets be clear, the problem is Apple pretty much telling the whole damn world they're using the internet wrong. Granted, everyone hates sites that start playing music the second they load but then Apple goes nuts and kills ANY/ALL buffering of audio/video that isn't explicitly initiated by a user gesture because Apple, apparently, thinks their users are too retarded to hit "back" if a site bothers them; fanboys agree too. This basically leaves the rest of us to hack the shit out of our applications if we dare try and manage any kind of sound effects. I know this isn't the place to rant...but i'll be damned if building ANY soft of interesting/interactive experience in HTML5 on the iPad isn't one facepalm after another...be it the 5mb cache limit that simply crashes the browser if a page has *too many (according to Apple) images or the difficulty to preload any sort of media to enhance UI - seriously, outside of wordpress blogs and rss readers, mobile Safari's implementation of HTML5 is pretty worthless. And so the dream of HTML5 "build once, play anywhere" value proposition is dead and we go back to deving native apps...at least this gives us good job security /rant

但我们要清楚的是,问题是苹果公司对整个该死的世界都说错了。当然,每个人都讨厌那些开始播放音乐的网站,但后来苹果疯了,并杀死了所有的音频/视频,而这些都不是由用户的手势直接引发的,因为显然,苹果认为他们的用户太迟钝了,如果一个网站让他们烦恼的话,他们就会被“退回”。粉丝也同意。如果我们敢于尝试和管理任何一种声音效果,这基本上就会让我们剩下的人来破解我们的应用程序。我知道这不是发泄的地方…但是,如果在iPad上构建任何一种有趣的/交互式的HTML5体验,那么我就不会被指责了。如果一个页面有太多(根据苹果的)图片或难以预加载任何类型的媒体来增强用户界面,那么它就是5mb的缓存限制(根据苹果的图片),在wordpress博客和rss阅读器之外,移动Safari的HTML5的实现是毫无价值的。因此,HTML5的梦想“构建一次,发挥任何地方”的价值主张已经消亡,我们又回到了原始的应用程序……至少这给了我们很好的工作保障。