Question

I have 3 versions of video.

QUESTION:

I need to show available quality of video if the main quality doesn't work or won't boot. How such it is possible to make?

version :high_mp4 do
  process encode_video: [:mp4, encode_params("720x720", HIGH_PARAMS).merge(version: Video::HIGH_VERSION) ]
  def full_filename(for_file=file)
    super.chomp(File.extname(super)) + '.mp4'
  end
end

version :medium_mp4 do
  process encode_video: [:mp4, encode_params("480x480", MEDIUM_PARAMS).merge(version: Video::MEDIUM_VERSION)]
  def full_filename(for_file=file)
    super.chomp(File.extname(super)) + '.mp4'
  end
end

version :low_mp4 do
  process encode_video: [:mp4, encode_params("320x320", LOW_PARAMS).merge(version: Video::LOW_VERSION)]
  def full_filename(for_file=file)
    super.chomp(File.extname(super)) + '.mp4'
  end
end

views:

= video.file.medium_mp4.url
Was it helpful?

Solution

I'm not sure about medium quality videos, but I know that a video wrapper like SublimeVideo has data-quality attribute that can allow switching between the two different versions.

If you have your own wrapper, you could use something like this to test the bandwidth and then trigger the appropriate source.

http://docs.sublimevideo.net/hd-switching

<video class="sublime" width="640" height="360" title="Midnight Sun"  preload="none">
  <source src="https://cdn.sublimevideo.net/vpa/ms_360p.mp4" />
  <source src="https://cdn.sublimevideo.net/vpa/ms_720p.mp4" data-quality="hd" />
  <source src="https://cdn.sublimevideo.net/vpa/ms_360p.webm" />
  <source src="https://cdn.sublimevideo.net/vpa/ms_720p.webm" data-quality="hd" />
</video>

If you're worried about the video not being available, when you include the sources, you could check to see if the file exists.

<video class="sublime" width="640" height="360" title="Midnight Sun"  preload="none">
  <% if File.exist?(@video.file(:low_mp4)) %>
    <source src="https://cdn.sublimevideo.net/vpa/ms_360p.mp4" />
  <% end %>
  <% if File.exist?(@video.file(:high_mp4)) %>
    <source src="https://cdn.sublimevideo.net/vpa/ms_720p.mp4" data-quality="hd" />
  <% end %>
  <source src="https://cdn.sublimevideo.net/vpa/ms_360p.webm" />
  <source src="https://cdn.sublimevideo.net/vpa/ms_720p.webm" data-quality="hd" />
</video>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top