How to create an upload feature for external video (like youtube) and the player for that video ?


I have a form to upload video from local directory. I use paperclip and acts as state machine for converting the video. I want to add a new feature to my application, the feature is the application can upload video from external link (like youtube, etc) too. I was thinking so simple, just add ‘external_url’ column to videos table to save the external video link.

The problem that I found, how the application can display the thumbnail of external video link and if the thumbnail clicked, the video can be played. I have used jquery-oembed plugin, but the plugin only for changing the link becomes the script to embed video, I need to display the video thumbnail too.

There is an easy way. I use acts as unvlogable plugin. This plugin provide the functions that I need.

First, install the plugin.

script/plugin install git://github.com/mamuso/acts_as_unvlogable.git

And don’t forget to install gems: youtube-g, xml-simple and hpricot. The plugin need them.

To display the video thumbnail:

videotron = UnvlogIt.new(video.external_url) 

link_to image_tag(videotron.thumbnail), :action => "view_video_answer", :id => video.id

To play the video:

videotron = UnvlogIt.new(video.external_url) 

videotron.embed_html(360, 240)

Let’s practice !

,

  1. Leave a comment

Leave a comment