Skip to content

Commit 290686a

Browse files
author
Bastian Bartmann
committed
fixed the preload option
1 parent b59bd03 commit 290686a

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

lib/podlove-web-player-rails/view_helpers.rb

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,34 @@ module ViewHelpers
55
# js method with given option parameters.
66
#
77
# @param [Hash] options options for the player
8-
# @option options [String] :src The location of an audio file, local ore remote.
9-
# @option options [String] :type The media type of the resource.
10-
# @option options [String] :mp4 The location of an audio file with the type mp4.
11-
# @option options [String] :mp3 The location of an audio file with the type mp3.
12-
# @option options [String] :ogg The location of an audio file with the type ogg.
13-
# @option options [String] :opus The location of an audio file with the type opus.
14-
# @option options [String] :poster The location of the cover image for the rich audio player.
8+
# @option options [string] :src The location of an audio file, local ore remote.
9+
# @option options [string] :type The media type of the resource.
10+
# @option options [string] :mp4 The location of an audio file with the type mp4.
11+
# @option options [string] :mp3 The location of an audio file with the type mp3.
12+
# @option options [string] :ogg The location of an audio file with the type ogg.
13+
# @option options [string] :opus The location of an audio file with the type opus.
14+
# @option options [string] :poster The location of the cover image for the rich audio player.
1515
# @option options [integer] :width (auto) The width of the player.
1616
# @option options [integer] :height The height of the player.
1717
# @option options [boolean] :loop (false) Loops the audio when it ends.
18-
# @option options [boolean] :preload (true) Start loading the audio as soon as possible,
18+
# @option options [string] :preload (auto) Start loading the video as soon as possible,
1919
# before the user clicks play. This might not work on all browsers.
20+
# Options are: 'auto', 'metadata' and 'none'
2021
# @option options [boolean] :autoplay (false) Start playing the audio as soon as it's ready.
2122
# This might not work on all (mobile) devices.
22-
# @option options [String] :duration (false) Enables display of duration without having to load the
23+
# @option options [string] :duration (false) Enables display of duration without having to load the
2324
# media file. Use seconds or timecode as a unit
2425
# (e.g. "3522" or "00:58:42")
2526
# @option options [boolean] :alwaysShowHours (true) Displays the time in 00:00:00 instead of 00:00.
2627
# @option options [boolean] :alwaysShowControls (true) Defines whether the player control bar is
2728
# permanently visible.
2829
# @option options [boolean] :volume (true) Disables the volume slider.
2930
# @option options [boolean] :progress (true) Disables the progress bar.
30-
# @option options [String] :captions URL to a WebVTT captions file.
31+
# @option options [string] :captions URL to a WebVTT captions file.
3132
# @option options [boolean] :chapters Takes chapter string in JSON format and builds an interactive
3233
# chapter table. Chapters must be written in the following format:
3334
# !{'start':'00:00:00.000', 'title':'Chapter One', 'image':''}
34-
# @option options [String] :chapterlinks (all) Option for the jumplink behaviour in chapter table.
35+
# @option options [string] :chapterlinks (all) Option for the jumplink behaviour in chapter table.
3536
# Options are: 'all' (all chapter links are clickable), 'buffered' (only
3637
# buffered chapters are clickable), 'false' (chapters are not linked)
3738
# @option options [boolean] :chaptersVisible (false) Defines the default visibility status of
@@ -42,7 +43,7 @@ module ViewHelpers
4243
# toggable summary module.
4344
# @option options [boolean] :downloadbuttonsVisible (false) Defines the default visibility of the
4445
# download buttons.
45-
# @return [String] HTML markup and JS call.
46+
# @return [string] HTML markup and JS call.
4647
def podloveaudio(options = {})
4748
podlove("audio", options)
4849
end
@@ -51,17 +52,18 @@ def podloveaudio(options = {})
5152
# js method with given option parameters.
5253
#
5354
# @param [Hash] options options for the player
54-
# @option options [String] :src This location of an video file, local ore remote.
55-
# @option options [String] :type The media type of the resource.
56-
# @option options [String] :mp4 The location of an audio file with the type mp4.
57-
# @option options [String] :webm The location of an audio file with the type webm.
58-
# @option options [String] :ogg The location of an audio file with the type ogg.
59-
# @option options [String] :poster The location of the poster frame for the video.
55+
# @option options [string] :src This location of an video file, local ore remote.
56+
# @option options [string] :type The media type of the resource.
57+
# @option options [string] :mp4 The location of an audio file with the type mp4.
58+
# @option options [string] :webm The location of an audio file with the type webm.
59+
# @option options [string] :ogg The location of an audio file with the type ogg.
60+
# @option options [string] :poster The location of the poster frame for the video.
6061
# @option options [integer] :width (auto) The width of the player.
6162
# @option options [integer] :height The height of the player.
6263
# @option options [boolean] :loop (false) Loops the video when it ends.
63-
# @option options [boolean] :preload (true) Start loading the video as soon as possible,
64+
# @option options [string] :preload (auto) Start loading the video as soon as possible,
6465
# before the user clicks play. This might not work on all browsers.
66+
# Options are: 'auto', 'metadata' and 'none'
6567
# @option options [boolean] :autoplay (false) Start playing the video as soon as it's ready.
6668
# This might not work on all (mobile) devices.
6769
# @option options [boolean] :fullscreen (true) Disables the fullscreen button for video.
@@ -74,11 +76,11 @@ def podloveaudio(options = {})
7476
# controls out when not hovering the video.
7577
# @option options [boolean] :volume (true) Disables the volume slider.
7678
# @option options [boolean] :progress (true) Disables the progress bar.
77-
# @option options [String] :captions URL to a WebVTT captions file.
79+
# @option options [string] :captions URL to a WebVTT captions file.
7880
# @option options [boolean] :chapters Takes chapter string in JSON format and builds an interactive
7981
# chapter table. Chapters must be written in the following format:
8082
# !{'start':'00:00:00.000', 'title':'Chapter One', 'image':''}
81-
# @option options [String] :chapterlinks (all) Option for the jumplink behaviour in chapter table.
83+
# @option options [string] :chapterlinks (all) Option for the jumplink behaviour in chapter table.
8284
# Options are: 'all' (all chapter links are clickable), 'buffered' (only
8385
# buffered chapters are clickable), 'false' (chapters are not linked)
8486
# @option options [boolean] :chaptersVisible (false) Defines the default visibility status of
@@ -89,7 +91,7 @@ def podloveaudio(options = {})
8991
# toggable summary module.
9092
# @option options [boolean] :downloadbuttonsVisible (false) Defines the default visibility of the
9193
# download buttons.
92-
# @return [String] HTML markup and JS call.
94+
# @return [string] HTML markup and JS call.
9395
def podlovevideo(options = {})
9496
podlove("video", options)
9597
end
@@ -98,8 +100,9 @@ def podlovevideo(options = {})
98100

99101
def podlove(type, options = {})
100102
id = "player_" + SecureRandom.hex(5)
103+
preload ||= "auto"
101104

102-
html = "<#{type} id='#{id}' preload=\"none\">"
105+
html = "<#{type} id='#{id}' preload=#{preload}>"
103106
html << "<source src='#{options[:src]}'"\
104107
"" + (options[:type] ? " type='#{options[:type]}'" : "") + "></source>" if options[:src]
105108
html << "<source src='#{options[:mp4]}' type='#{type}/mp4'></source>" if options[:mp4]
@@ -109,7 +112,7 @@ def podlove(type, options = {})
109112
html << "<source src='#{options[:webm]}' type='#{type}/webm'></source>" if options[:webm]
110113
html << "</#{type}>"
111114

112-
[:src, :type, :mp4, :mp3, :ogg, :opus, :webm].each{ |key| options.delete(key) }
115+
[:src, :type, :mp4, :mp3, :ogg, :opus, :webm, :preload].each{ |key| options.delete(key) }
113116

114117
script = "jQuery('##{id}').podlovewebplayer(#{options.to_json});"
115118

0 commit comments

Comments
 (0)