回形针视频上传 [英] Paperclip Video Upload

查看:225
本文介绍了回形针视频上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的帖子中启用视频上传。
无法显示视频。视频上传,我可以确认,虽然我设法右键点击视频区域,并下载它。问题是如何正确查看它。



迁移:

  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 def
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
结束
结束

发布模型

  class Post< ActiveRecord :: Base 
default_scope:order => 'created_at desc'
attr_accessible:content,:title,:photo,:photo_delete,:video,:video_delete,:dependent => :销毁
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 => 浮动:离开 %GT;
<%= f.check_box:video_delete,:style => 浮动:离开 %GT; & nbsp;删除影片
< / div>< br />
< div class =visible-xs>
<%= f.file_field:video,:style => 中心%>
<%= f.check_box:video_delete,:style => 中心%> & nbsp;删除影片
< / div>< br />

发布视频中的视频部分

 <%if @ post.video? %GT; 
< h1 class =center>
<%= @ post.title%>
< / h1>< br />
<%= video_path @ post.video.url%>
<%end%>

我也尝试过使用video_tag,这些都不起作用,当我尝试使用:

 < iframe width =490height =275src =<%= video_path @ post.video.url%>  frameborder =0allowfullscreen autoplay =true> 
< / iframe>

我得到一个不会玩的玩家。
如果你仔细观察,可能会很感激,也许可以帮助我想出一个可行的解决方案。您应该使用视频标记,而不是<$ c $ c> iframe
(只有 video 标签有自动播放选项)。在此查看浏览器支持哪些格式: http://caniuse.com/#search=video

如果您想要跨浏览器解决方案,请尝试VideoJS - http:// www.videojs.com/
在这里你可以得到一个Rails插件 - https:// github .com / seanbehan / videojs_rails


I'm trying to enable video upload in my post. Can't get it to display the video. The video gets uploaded, I can confirm that while i manage to right click on the video area and download it. The problem is how to view it correctly.

Migration:

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

Post Model

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

Video part in my post _form

<div class="visible-md visible-lg">
  <%= f.file_field :video, :style => "float: left;" %>
  <%= f.check_box :video_delete, :style => "float: left;" %> &nbsp;Delete video
  </div><br />
<div class="visible-xs">
  <%= f.file_field :video, :style => "center" %>
  <%= f.check_box :video_delete, :style => "center" %> &nbsp;Delete video
</div><br />

Video part in Post Show

<% if @post.video? %>
<h1 class="center">
<%= @post.title %>
</h1><br />
<%= video_path @post.video.url %>       
<% end %>

I have also tried with video_tag which don't work and when I try with:

<iframe width="490" height="275" src="<%= video_path @post.video.url %>" frameborder="0" allowfullscreen autoplay="true">
            </iframe>

I get a player that won't play. Would really appreciate if you look it through and maybe help me to come up with a solution that will work. Thanks!

解决方案

You should use video tag, not iframe (only video tag has autoplay options). Check here what formats are supported by what browser: http://caniuse.com/#search=video

If you want crossbrowser solution, try VideoJS - http://www.videojs.com/ Here you can get a Rails plugin - https://github.com/seanbehan/videojs_rails

这篇关于回形针视频上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆