2014-03-07 38 views
0

我试图更改/删除我的视频这是在我的start.htmlGWT:removeAttribute没有工作?

<video id="video" preload="auto" autoplay="true" loop="loop" 
    muted="muted" volume="0"> 
<source 
      src="clip0012.mp4" type="video/mp4"> 
</video> 

我打电话这样的:

Element elem = DOM.getElementById("video_background"); 
    elem.getFirstChildElement().removeAttribute("src"); 
elem.getFirstChildElement().setAttribute("src", "clip0022.mp4"); 

我没有得到任何错误等视频clip0012仍显示,但为什么?

+1

代码片段中没有包含id“video_background”的元素。 –

+0

改变它,但没有发生 – user3110458

+0

在javascript中它是:getElementById('videoSource')。src =“X.m4v”; – user3110458

回答

0

试试这个(见注释在代码的详细信息):

的java:

//Get old Video Element 
    Element oldVideoElement=RootPanel.get("video").getElement(); 

    //Create a new Video Element 
    VideoElement newVideoElement=Document.get().createVideoElement(); 
    newVideoElement.setId("video"); 
    newVideoElement.setPreload("auto"); 
    newVideoElement.setAttribute("autoplay","true"); 
    newVideoElement.setAttribute("loop","loop"); 
    newVideoElement.setAttribute("muted","muted"); 
    newVideoElement.setAttribute("volume","0"); 

    //Create a new Source Element 
    SourceElement sourceElement = Document.get().createSourceElement(); 
    sourceElement.setSrc("movie.mp4"); 
    sourceElement.setType("video/mp4"); 

    //Append new source Element in new video Element 
    newVideoElement.appendChild(sourceElement); 

    //Append new video element in video div 
    RootPanel.get("videoDiv").getElement().appendChild(newVideoElement); 

    //remove old video element from its parent 
    oldVideoElement.removeFromParent(); 

HTML:

<div id="videoDiv"> 
    <video id="video" preload="auto" autoplay="true" loop="loop" 
     muted="muted" volume="0"> 
     <source src="clip0012.mp4" type="video/mp4"> 
    </video> 
</div> 
0

用这个代替:

DOM.getElementById("video").setAttribute("src", "clip0022.mp4");