请帮助解决问题。
我实现了加载视频文件。我使用了一个宝石paperclip-av-transcoder。
模型:
class Video < ActiveRecord::Base
has_attached_file :video,
:url => ":localhost/system/:class/:attachment/:id/:style/:filename",
:path => ":rails_root/public/system/:class/:attachment/:id/:style/:filename",
:styles => {
:medium => { :geometry => "640x480", :format => 'flv' },
:thumb => { :geometry => "200x100#", :format => 'jpg', :time => 10 }
}, :processors => [:transcoder]
validates_attachment_content_type :video, :content_type => ["video/mp4", "video.mov", "video/mpeg","video/mpeg4", "image/jpg", "image/jpeg"]
end
控制器:
def create
@video = Video.new(video_params)
if @video.save
flash[:success] = :video_created
redirect_to @video
else
flash.now[:error] = :video_not_created
redirect_to @video
end
end
show.html.erb:
<video width="320" height="240" controls>
<source src="<%= @video.video_file_name %>" type="<%= @video.video_content_type %>">
</video>
生成的视频文件已加载到系统中,但未显示。
萤火虫显示错误的方式:<video width="320" height="240" controls="">
<source src="mmm.mp4" type="video/mp4">
</video>
实际路径是:
/home/kalinin/rails/vd/public/system/videos/videos/17/medium/mmm.flv
我不明白如何在屏幕上播放视频。
答案 0 :(得分:3)
尝试以下代码
<%= video_tag @video.video.path(:medium), type: @video.video_content_type %>