HTML5音频:Android上的Chrome不会在PC上自动播放歌曲与Chrome [英] HTML5 Audio: Chrome on Android doesn't automatically play song vs Chrome on PC does

查看:367
本文介绍了HTML5音频:Android上的Chrome不会在PC上自动播放歌曲与Chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经制作了一个HTML5 iPod。



您可以在这里试用。 $ b

http://inventikasolutions.com/demo/iPod



在PC上,使用Chrome。如果我导航到一首歌曲,它会自动开始播放。
但在Android上使用Chrome时,它不会播放歌曲。我必须再次点击播放/暂停按钮才能播放音频。



当您选择要播放的歌曲时,以下是运行的代码:

  audioPlayer.src = songurl [number]; 
audioPlayer.oncanplaythrough =isAppLoaded;
audioPlayer.autoplay =autoplay;
audioPlayer.addEventListener('ended',nextSong,false);
document.getElementById(player)。appendChild(audioPlayer);

这里是播放/暂停代码。

  if(audioPlayer.paused)
{
audioPlayer.play();
$(#pauseindicator)。hide();
$(#playindicator)。show();
}
else
{
audioPlayer.pause();
$(#pauseindicator)。show();
$(#playindicator)。hide();
}

这可能与'autoplay'变量有关吗?
Android中的默认浏览器立即播放歌曲。



谢谢。

解决方案

请参阅此链接...



http:/ /code.google.com/p/chromium/issues/detail?id=138132



Chrome不允许应用程式在没有明确操作的情况下播放HTML5音讯由用户操作,类似于iOS的处理方式,但与Android浏览器处理它的方式不同。



Autoplay在Android上不受尊重,因为它会花费数据使用。


I've made an HTML5 iPod.

You can try it here.

http://inventikasolutions.com/demo/iPod

On a PC, while using Chrome. If I navigate to a song, it starts playing automatically. But while using Chrome on Android it doesn't play the song. I have to hit the play/pause button again to play the audio.

Here is the code which runs, when you select the song to play:

audioPlayer.src=songurl[number];
audioPlayer.oncanplaythrough = "isAppLoaded";
audioPlayer.autoplay = "autoplay";
audioPlayer.addEventListener('ended',nextSong,false);
document.getElementById("player").appendChild(audioPlayer);

and here is the play/pause code.

        if (audioPlayer.paused)
        {
        audioPlayer.play();
        $("#pauseindicator").hide();
        $("#playindicator").show();
        }
        else
        {
        audioPlayer.pause();
        $("#pauseindicator").show();
        $("#playindicator").hide();
        }

Could it have some thing to do with the 'autoplay' variable? The default browser in Android plays the song immediately.

Thanks.

解决方案

Please refer this link ...

http://code.google.com/p/chromium/issues/detail?id=138132

Chrome does not allow applications to play HTML5 audio without an explicit action by the user, similar to how it is handled by iOS, but differently than the stock Android browser handles it.

Autoplay is not honored on android as it will cost data usage.

这篇关于HTML5音频:Android上的Chrome不会在PC上自动播放歌曲与Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆