Module: Bitmovin::Player::Rails::Helper

Defined in:
lib/bitmovin/player/rails/helper.rb

Instance Method Summary collapse

Instance Method Details

#bitmovin_player(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bitmovin/player/rails/helper.rb', line 7

def bitmovin_player(options={})
	container = options.delete(:container) || "bitmovin-#{SecureRandom.hex[0...5]}"
	width = options.delete(:width)
	height = options.delete(:height)
	options[:style] = options[:style] || {}
	options[:style][:width] = width unless width.nil?
	options[:style][:height] = height unless height.nil?


	options[:source] = options[:source] || {}
	options[:source][:dash] = options[:source][:dash] || options.delete(:dash) if (options[:source][:dash] || options[:dash])
	options[:source][:hls] = options[:source][:hls] || options.delete(:hls) if (options[:source][:hls] || options[:hls])
	options[:source][:progressive] = options[:source][:progressive] || options.delete(:progressive) if (options[:source][:progressive] || options[:progressive])
	options[:source][:poster] = options[:source][:poster] || options.delete(:poster) if (options[:source][:poster] || options[:poster])

	version = Rails.configuration.bitmovin_player["version"]
	setup = "bitmovin.player"
	setup = "bitdash" if version.include?("5")

	options[:key] = Rails.configuration.bitmovin_player["license_key"]

	result = <<-EOS
<div id="#{container}"></div>
<script type="text/javascript">
var conf = #{JSON.pretty_generate(options)};
var player = #{setup}("#{container}");
player.setup(conf).then(function(value) {
		// Success
		console.log("Successfully created bitmovin player instance");
}, function(reason) {
		// Error!
		console.log("Error while creating bitmovin player instance");
});
</script>
EOS
	result.html_safe
end

#bitmovin_player_scriptObject



3
4
5
# File 'lib/bitmovin/player/rails/helper.rb', line 3

def bitmovin_player_script
	javascript_include_tag Rails.configuration.bitmovin_player["cdn_url"]
end