package eu.dnetlib.client.shared;

import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Widget;

public class VideoHtml  implements IsWidget{
	private HTML videoHtml;
	private String videoSrc;
	private String videoType;
	private String posterSrc;

	public VideoHtml(String Videosrc, String videoType, String posterSrc) {
		this.videoSrc = Videosrc;
		this.videoType = videoType;
		this.posterSrc = posterSrc;
		String video = "<video  preload='none' width='400' height='360' controls='true' ";
		if (posterSrc != null) {
			video += "poster='" + posterSrc + "' ";

		}
		video += " >";
		video += "<source ";
		// if (!videoType.isEmpty())
		{
			video += " type='" + videoType + "' ";

		}

		video += " src='" + Videosrc + "' ></source> " + " </video>";

		videoHtml = new HTML(video);

	}
    public VideoHtml(String Videosrc, String posterSrc) {
        this.videoSrc = Videosrc;
        this.videoType = null;
        this.posterSrc = null;
        String video = "<video  preload='none' width='400' height='360' controls='true' ";
        if (posterSrc != null) {
            video += "poster='" + posterSrc + "' ";

        }
        video += " >";
        video += "<source ";


        video += " src='" + Videosrc + "' ></source> " + " </video>";

        videoHtml = new HTML(video);

    }
	public HTML getVideo() {
		return this.videoHtml;
	}

	public String getVideoString() {
		return this.videoHtml.getHTML();
	}

	/*
	 * Call this function after adding video to the panel changes player with
	 * mediaelementplayer.min
	 */

	public static native void displayplayer() /*-{
												$wnd.displayPlayer();
												}-*/;

	public void setPosterSrc(String posterSrc) {
		this.posterSrc = posterSrc;
		String video = "<video  preload='none' width='440' height='360' controls='true' ";
		if (posterSrc != null) {
			video += "poster='" + posterSrc + "' ";

		}
		video += " >";
		video += "<source ";

		video += " type='" + videoType + "' ";

		video += " src='" + videoSrc + "' ></source> " + " </video>";

		videoHtml = new HTML(video);

	}

	public Widget asWidget() {
 		return videoHtml;
	}

}
