【发布时间】:2013-10-13 21:18:37
【问题描述】:
我正在尝试在我的帖子中启用视频上传。 无法让它显示视频。视频已上传,我可以确认,虽然我设法右键单击视频区域并下载它。问题是如何正确查看。
迁移:
class AddAttachmentVideoToPosts < ActiveRecord::Migration
def self.up
change_table :posts do |t|
t.attachment :video
end
end
def self.down
drop_attached_file :posts, :video
end
end
def change
create_table :videos do |t|
t.string :video_file_name
t.string :video_content_type
t.integer :video_file_size
t.datetime :video_updated_at
t.timestamps
end
end
后模型
class Post < ActiveRecord::Base
default_scope :order => 'created_at desc'
attr_accessible :content, :title, :photo, :photo_delete, :video, :video_delete, :dependent => :destroy
has_attached_file :photo, :styles => { :thumb => "600x600#", :medium => "300x300#", :small => "160x160#"}
has_attached_file :video
validates_uniqueness_of :title
validates_presence_of :title, :content
has_destroyable_file :photo, :video
end
我的帖子_form中的视频部分
<div class="visible-md visible-lg">
<%= f.file_field :video, :style => "float: left;" %>
<%= f.check_box :video_delete, :style => "float: left;" %> Delete video
</div><br />
<div class="visible-xs">
<%= f.file_field :video, :style => "center" %>
<%= f.check_box :video_delete, :style => "center" %> Delete video
</div><br />
展后视频部分
<% if @post.video? %>
<h1 class="center">
<%= @post.title %>
</h1><br />
<%= video_path @post.video.url %>
<% end %>
我也尝试过 video_tag 不起作用,当我尝试使用时:
<iframe width="490" height="275" src="<%= video_path @post.video.url %>" frameborder="0" allowfullscreen autoplay="true">
</iframe>
我得到一个不会玩的玩家。 如果您仔细查看并可能帮助我想出一个可行的解决方案,我将不胜感激。谢谢!
【问题讨论】:
-
取决于你想要什么。请记住,托管您自己的用户上传的视频存在一些问题。就像您确保获得正确的编码以实现跨浏览器兼容性一样。 jplayer.org 是很棒的开源播放器,可以处理您的视图层。如果你想要高跨浏览器兼容性,你需要为 jplayer 提供多种编码的路径。您可以使用 zen coder 之类的服务。这确实很昂贵,但他们都有一定程度的免费开发帐户来学习和试验他们的系统。
-
谢谢,试试jplayer :)
-
@TyrelRichey 我已经安装了 jplayer,加载了皮肤,现在有了一个视频播放器外壳。但我现在不知道如何调用视频以便播放器工作。我有这个 jquery:
-
-
让示例视频播放,这意味着它会加载所有已安装的文件。虽然当我调用 m4v 时它不会播放我的视频:“”
标签: ruby-on-rails ruby file-upload paperclip ruby-on-rails-4