开发者

Vaadin framework play video

开发者 https://www.devze.com 2023-02-14 14:38 出处:网络
Can I play video using Vaadin framewotk ? The main idea is loading video files from开发者_如何学运维 local drive in flv or avi formats and play it in web using vaadin framework.

Can I play video using Vaadin framewotk ? The main idea is loading video files from开发者_如何学运维 local drive in flv or avi formats and play it in web using vaadin framework. Thanks.


There is a sample in the Sampler: http://demo.vaadin.com/sampler/#FlashEmbed You can see the source by clicking 'view source', and it will show you something like this:

Embedded e = new Embedded(null, new ExternalResource(
                "http://www.youtube.com/v/meXvxkn1Y_8&hl=en_US&fs=1&"));
e.setMimeType("application/x-shockwave-flash");
e.setParameter("allowFullScreen", "true");
e.setWidth("320px");
e.setHeight("265px");
addComponent(e);

Obviously, you'll want to change the ExternalResource to something else (e.g FileResource, ClassResource, StreamResource, ...) in order to play local files.


Vaadin version 6.7 brought a new class Video that uses the new HTML5 "video" element to embed video on a page.

My posting on the Vaadin Forum provides the source code for an example app.

The main part of that code, when populating a window or layout:

Video v = new Video( "video" ); // Instantiate video player widget.
// Specify a list of your video in one or more formats.
// Different browsers support various different video formats.
v.setSources( 
    new ExternalResource( "http://www.example.com/media/example_video.mp4" ),
    new ExternalResource( "http://www.example.com/media/example_video.ogv" ) 
); 
v.setWidth( "640px" ); // Set size of the video player's display area on-screen.
v.setHeight( "360px" );
this.addComponent( v ); // Add the component to the window or layout.

Oops, I just re-read you posting -- you want to play local video files. Do you mean local to the user's computer or the Vaadin app server-side computer? Either way, you may be able to manipulate the "ExternalResource" seen above, or another subclass of Vaadin Resource to access a local file.


You can use the Embedded Class to embed videos.


NOTE: This is for local files:

        FileResource fileResource = new FileResource(new File("/Users/user/Downloads/DBTI_1991_teaser_HD.mp4"));
        Video vd = new Video();
        vd.setAutoplay(true);
        vd.setSource(fileResource);
        this.addComponent(vd);


Another alternative is the Vaadin add-on "YouTubePlayer" if you want to access a video specifically from YouTube.com.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号