简体   繁体   English

TypeError:undefined'不是函数(评估'myAudio.play()')“

[英]TypeError: undefined' is not a function (evaluating 'myAudio.play()')"

Audio file can not play in Safari.. It gives an Error. 音频文件无法在Safari中播放。它给出了一个错误。

TypeError: 'undefined' is not a function (evaluating 'myAudio.play()')

Here is my HTML code. 这是我的HTML代码。

<audio>
  <source src="audio/horse.ogg" type="audio/ogg">
  <source src="audio/horse.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>    

Here is my JavaScript Code 这是我的JavaScript代码

myAudio = document.getElementsByTagName('audio')[0];
if (typeof myAudio.loop == 'boolean'){
  myAudio.loop = true;
}
else{
  myAudio.addEventListener('ended', function() {
  this.currentTime = 0;
  this.play();
   }, false);
}   
myAudio.play();

I have only One Audio Tag in HTML. 我在HTML中只有一个音频标签。

I had similar problem on my windows pc. 我在Windows PC上也遇到类似的问题。

So to test, I created a simple HTML file with one red big dot and clicking which would play the audio. 因此,为了进行测试,我创建了一个带有一个红色大点的简单HTML文件,然后单击该文件将播放音频。 It worked on all HTML5 compatible browsers EXCEPT safari. 它可用于所有HTML5兼容的浏览器(野生动物园除外)。 I spent whole day and tried more than 100 different solutions to get it to work on on safari, but no luck. 我花了整整一天的时间,尝试了100多种不同的解决方案,使其能够在Safari中使用,但是没有运气。

At the end, I installed QuickTime (latest version) and it solved 50% of the problem. 最后,我安装了QuickTime(最新版本),它解决了50%的问题。

Rest 50% of the problem was the code structure. 剩下的50%的问题是代码结构。

<audio id="audio1" src="audio/guestProfile.ogg" type="audio/ogg" ></audio>
<audio id="audio1" src="audio/guestProfile.mp3" type="audio/mpeg"  ></audio>

It didn't like the above code. 它不喜欢上面的代码。 So I had to change it to following: 所以我不得不将其更改为以下内容:

<audio id="audio1">
    <source src="audio/guestProfile.ogg" type="audio/ogg">
    <source src="audio/guestProfile.mp3" type="audio/mpeg">
    Your browser does not support the audio tag.
</audio>

This may not be the neat & perfect solution. 这可能不是一个完美的解决方案。 But it worked for me. 但这对我有用。

It will never work on Windows Safari because the last Safari for Windows was released in 2010. And that's the reason why HTML5: <audio> or <video> tags does not work in Windows Safari. 它永远不会在Windows Safari上运行,因为最新的Windows Safari于2010年发布。这就是HTML5: <audio><video>标记在Windows Safari中不起作用的原因。 Test yourself 测试自己

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 myAudio.play()不是函数 - myAudio.play() is not a function TypeError:undefined不是函数(评估调度) - TypeError: undefined is not a function (evaluating dispatch) myaudio 不是 function - myaudio is not a function TypeError:undefined不是一个函数(评估“ categories.map”) - TypeError: undefined is not a function (evaluating 'categories.map') TypeError:undefined不是函数(评估&#39;$(“#typed”)。typed&#39;) - TypeError: undefined is not a function (evaluating '$(“#typed”).typed') TypeError:'undefined'不是函数(评估'mockBackend.expectPost( - TypeError: 'undefined' is not a function (evaluating 'mockBackend.expectPost( TypeError:undefined不是一个函数(评估&#39;document.getsElementsByClassName(&#39;&#39;) - TypeError: undefined is not a function (evaluating 'document.getsElementsByClassName('') TypeError:'undefined'不是函数(评估'sinon.spy()') - TypeError: 'undefined' is not a function (evaluating 'sinon.spy()') TypeError:未定义不是函数(正在评估userItems.map) - TypeError: undefined is not a function (evaluating userItems.map) TypeError:未定义不是函数。 iOS Safari评估功能。 CoffeeScript - TypeError: Undefined is not a function. iOS Safari Evaluating function. CoffeeScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM