Fix bug.
This commit is contained in:
parent
c8b21416c1
commit
986cca8c5c
|
@ -151,8 +151,8 @@ class AdBannersController < ApplicationController
|
|||
extra_before_html = ""
|
||||
extra_after_html = ""
|
||||
if has_jplayer
|
||||
extra_before_html = ActionController::Base.helpers.stylesheet_link_tag("banner/jplayer.blue.monday.min.css")
|
||||
extra_after_html = ActionController::Base.helpers.javascript_include_tag("banner/jquery.jplayer.min.js")
|
||||
extra_before_html = "\n" + ActionController::Base.helpers.stylesheet_link_tag("banner/jplayer.blue.monday.min.css") + "\n" +
|
||||
ActionController::Base.helpers.javascript_include_tag("banner/jquery.jplayer.min.js") + "\n"
|
||||
end
|
||||
base_image = adbanner.base_image.nil? ? 1 : adbanner.base_image
|
||||
adbanner_title_escape = adbanner.title.to_s.gsub('"','"')
|
||||
|
|
|
@ -8,7 +8,7 @@ class AdImage
|
|||
mount_uploader :video_snapshot, BannerImageUploader
|
||||
mount_uploader :video_file, BannerUploader
|
||||
mount_uploader :video_file_webm, BannerUploader
|
||||
|
||||
field :default_video_snapshot, type: Boolean, default: false
|
||||
field :auto_convert_video, type: Boolean, default: false
|
||||
field :title, type: String, localize: true
|
||||
field :context, type: String, localize: true
|
||||
|
@ -33,14 +33,39 @@ class AdImage
|
|||
scope :can_display, ->{self.and(AdImage.unscoped.or({:postdate.lte=>Time.now},{:postdate=>nil}).selector,AdImage.unscoped.or({:deadline.gte=>Time.now},{:deadline=>nil}).selector)}
|
||||
scope :is_expired, ->{self.and(AdImage.unscoped.or({:deadline.lte=>Time.now}).selector)}
|
||||
scope :not_expired, ->{self.and(AdImage.unscoped.or({:deadline.gte=>Time.now},{:deadline=>nil}).selector)}
|
||||
|
||||
after_save do
|
||||
if (self.video_file_changed? || self.auto_convert_video_changed?) && self.auto_convert_video
|
||||
Thread.new do
|
||||
self.generate_webm
|
||||
before_save do
|
||||
unless @skip_callback
|
||||
if self.video_snapshot_changed?
|
||||
self.default_video_snapshot = false
|
||||
end
|
||||
end
|
||||
end
|
||||
after_save do
|
||||
unless @skip_callback
|
||||
if (self.video_file_changed? || self.auto_convert_video_changed?) && self.auto_convert_video
|
||||
Thread.new do
|
||||
self.generate_webm
|
||||
end
|
||||
end
|
||||
if self.video_file? && self.video_file_changed? && (!(self.video_snapshot?) || self.default_video_snapshot)
|
||||
Thread.new do
|
||||
self.generate_video_snapshot
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
def generate_video_snapshot
|
||||
if self.video_file?
|
||||
self.default_video_snapshot = true
|
||||
self[:video_snapshot] = File.basename(self.video_file.file.path).split(/\.[^.]+$/)[0] + ".jpg"
|
||||
FileUtils.mkdir_p(File.dirname(self.video_snapshot.file.path))
|
||||
system("tmp/ffmpeg/ffmpeg -i #{self.video_file.file.path} -vframes 1 #{self.video_snapshot.file.path}")
|
||||
@skip_callback = true
|
||||
self.save
|
||||
@skip_callback = false
|
||||
true
|
||||
end
|
||||
end
|
||||
def generate_webm
|
||||
video_path = self.video_file.path rescue nil
|
||||
if !video_path.blank?
|
||||
|
@ -49,7 +74,10 @@ class AdImage
|
|||
flag = system("tmp/ffmpeg/ffmpeg -i #{video_path} -c:v libvpx-vp9 -crf 35 -b:v 0 -b:a 96k -c:a libopus -filter:v fps=20 #{video_webm} -cpu-used #{core_num}")
|
||||
if flag
|
||||
self.video_file_webm = File.open(video_webm)
|
||||
@skip_callback = true
|
||||
self.save
|
||||
@skip_callback = false
|
||||
true
|
||||
else
|
||||
puts "generate webm failed"
|
||||
end
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
<% end %>
|
||||
</td>
|
||||
<td>
|
||||
<%= image.title rescue "" %>
|
||||
<%= image.title.to_s.html_safe rescue "" %>
|
||||
<% if can_edit_or_delete?(@banner) %>
|
||||
<div class="quick-edit">
|
||||
<ul class="nav nav-pills">
|
||||
|
|
|
@ -209,14 +209,15 @@
|
|||
})
|
||||
if (typeof(default_video_data)=='undefined'){
|
||||
var default_video_data = {
|
||||
cssSelectorAncestor: "#jp_container_<%= i %>",
|
||||
ready: function () {
|
||||
$(this).jPlayer("setMedia", {
|
||||
title: "Big Buck Bunny Trailer",
|
||||
m4v: "http://www.jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v",
|
||||
ogv: "http://www.jplayer.org/video/ogv/Big_Buck_Bunny_Trailer.ogv",
|
||||
webmv: "http://www.jplayer.org/video/webm/Big_Buck_Bunny_Trailer.webm",
|
||||
poster: "http://www.jplayer.org/video/poster/Big_Buck_Bunny_Trailer_480x270.png"
|
||||
})
|
||||
$(this).jPlayer("setMedia", {
|
||||
title: "Big Buck Bunny Trailer",
|
||||
m4v: "http://www.jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v",
|
||||
ogv: "http://www.jplayer.org/video/ogv/Big_Buck_Bunny_Trailer.ogv",
|
||||
webmv: "http://www.jplayer.org/video/webm/Big_Buck_Bunny_Trailer.webm",
|
||||
poster: "http://www.jplayer.org/video/poster/Big_Buck_Bunny_Trailer_480x270.png"
|
||||
})
|
||||
},
|
||||
play: function() { // To avoid multiple jPlayers playing together.
|
||||
play_<%= i %>_flag = true;
|
||||
|
@ -365,7 +366,8 @@
|
|||
//jPlayer_<%= i %>_data["autoPlay"] = <%= @autoplay_video == true %>;
|
||||
jPlayer_<%= i %>["ready"] = function () {
|
||||
$(this).jPlayer("setMedia", jPlayer_<%= i %>_data);
|
||||
if ($(this).parents(".ba-banner-widget-youtube").eq(0).find(".w-ba-banner__slide").index($(this).parents(".w-ba-banner__slide").eq(0))==0){
|
||||
var slides = $(this).parents('.cycle-slideshow').data('cycle.opts').slides;
|
||||
if (slides && slides.index($(this).parents(".w-ba-banner__slide").eq(0))==0){
|
||||
<% if @autoplay_video == true %>
|
||||
var $video_ele = $(this).find('video');
|
||||
if ($video_ele.length>0){
|
||||
|
|
|
@ -3,12 +3,19 @@ require 'fileutils'
|
|||
get 'ad_banners/widget'
|
||||
if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console')
|
||||
Thread.new do
|
||||
ad_images = AdImage.where(:video_file.ne=>nil,:video_snapshot=>nil).to_a
|
||||
ad_images.each do |ad_image|
|
||||
ad_image[:video_snapshot] = File.basename(ad_image.video_file.file.path).split(/\.[^.]+$/)[0] + ".jpg"
|
||||
FileUtils.mkdir_p(File.dirname(ad_image.video_snapshot.file.path))
|
||||
system("tmp/ffmpeg/ffmpeg -i #{ad_image.video_file.file.path} -vframes 1 #{ad_image.video_snapshot.file.path}")
|
||||
ad_image.save
|
||||
s = Site.first
|
||||
update_flag = s.respond_to?(:tmp_flags)
|
||||
need_update = !update_flag || !(s.tmp_flags.include?('adf1'))
|
||||
if need_update
|
||||
ad_images = AdImage.where(:video_file.ne=>nil,:video_snapshot=>nil).to_a
|
||||
ad_images.each do |ad_image|
|
||||
ad_image.generate_video_snapshot
|
||||
end
|
||||
if update_flag
|
||||
s = OrbitHelper::SharedHash['current_site']['site'] rescue Site.first
|
||||
s.tmp_flags << 'adf1'
|
||||
s.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue