English 中文(简体)
我如何在不向OMM投电的情况下适当删除第html5号录音?
原标题:How do I remove properly html5 audio without appending to DOM?

With Javascript, I have a function that creates an audio element with createElement("audio"), and start playing in loop without using appendChild(), I mean without appending it to the DOM. The element created is kept in a variable, let s called it music1:

music = document.createElement("audio");
 music.addEventListener("loadeddata", function() {
 music.play();
});
music.setAttribute("src", music_Source);

What I would like to do, is to change the music played, if possible using the same function, and storing the element in the same variable.

我这样做的是,在以上法典之前:

if(typeof(music) == "object") {
 music.pause();
 music = null;
}

但是,如果我删除),那么第一个音乐会会继续发挥作用,第二个音乐会也同时起作用,因此我认为,第一个音乐总是在文件/记忆中起一定的作用。 此外,<代码>music = 无似乎无用。 我不想 use。

Do you have any idea to properly remove the first music, delete the element, or so on?

实际上,肯尼斯评论是正确的,我试图只是改变rc属性,而不是修改“肌肉”变数(要么将其定为无效,要么重新定性为`工具'),似乎也做了工作。 因此,记录: 此处变化的每个来源的职能是:

if(typeof(music) != "object") {
  //audio element does not exist yet:
  music = document.createElement("audio");
  music.addEventListener("loadeddata", function() {
    music.play();
  });
}
music.setAttribute("src", music_Source);
最佳回答

这样做的最好方式是改变rc锁,而不是删除。

music.setAttribute( src ,theNewSource); //change the source
music.load(); //load the new source
music.play(); //play

因此,你总是处理同一物体,这样你就更经常地打过管理局,也避免了你同时有两个角色的问题。

还确保你使用有效载荷法装上新音响,否则它将保持旧音。

问题回答

原始物体将予删除,但只有停车场收集商确定时间。 其<代码>audio可能使事情复杂化,使浏览器难以作出这一确定。

因此,是的,只是重新使用原始物体。

While reusing the HTMLAudioElements is definitely the best option -for completeness- you should be able to dispose it by just clearing the src or srcObj:

music.srcObj = null;

这多或少让你们的行凶者理事会知道,这个内容已经准备好去除。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签