|
1 |
| -module Podlove |
2 |
| - module Web |
3 |
| - module Player |
4 |
| - module Rails |
5 |
| - module ViewHelpers |
6 |
| - # Generates the HTML markup needed for the podlove audio player and calls the podlovewebplayer |
7 |
| - # js method with given option parameters. |
8 |
| - # |
9 |
| - # @param [Hash] options options for the player |
10 |
| - # @option options [String] :src The location of an audio file, local ore remote. |
11 |
| - # @option options [String] :type The media type of the resource. |
12 |
| - # @option options [String] :mp4 The location of an audio file with the type mp4. |
13 |
| - # @option options [String] :mp3 The location of an audio file with the type mp3. |
14 |
| - # @option options [String] :ogg The location of an audio file with the type ogg. |
15 |
| - # @option options [String] :opus The location of an audio file with the type opus. |
16 |
| - # @option options [String] :poster The location of the cover image for the rich audio player. |
17 |
| - # @option options [integer] :width (auto) The width of the player. |
18 |
| - # @option options [integer] :height The height of the player. |
19 |
| - # @option options [boolean] :loop (false) Loops the audio when it ends. |
20 |
| - # @option options [boolean] :preload (true) Start loading the audio as soon as possible, |
21 |
| - # before the user clicks play. This might not work on all browsers. |
22 |
| - # @option options [boolean] :autoplay (false) Start playing the audio as soon as it's ready. |
23 |
| - # This might not work on all (mobile) devices. |
24 |
| - # @option options [String] :duration (false) Enables display of duration without having to load the |
25 |
| - # media file. Use seconds or timecode as a unit |
26 |
| - # (e.g. "3522" or "00:58:42") |
27 |
| - # @option options [boolean] :alwaysShowHours (true) Displays the time in 00:00:00 instead of 00:00. |
28 |
| - # @option options [boolean] :alwaysShowControls (true) Defines whether the player control bar is |
29 |
| - # permanently visible. |
30 |
| - # @option options [boolean] :volume (true) Disables the volume slider. |
31 |
| - # @option options [boolean] :progress (true) Disables the progress bar. |
32 |
| - # @option options [String] :captions URL to a WebVTT captions file. |
33 |
| - # @option options [boolean] :chapters Takes chapter string in JSON format and builds an interactive |
34 |
| - # chapter table. Chapters must be written in the following format: |
35 |
| - # !{'start':'00:00:00.000', 'title':'Chapter One', 'image':''} |
36 |
| - # @option options [String] :chapterlinks (all) Option for the jumplink behaviour in chapter table. |
37 |
| - # Options are: 'all' (all chapter links are clickable), 'buffered' (only |
38 |
| - # buffered chapters are clickable), 'false' (chapters are not linked) |
39 |
| - # @option options [boolean] :chaptersVisible (false) Defines the default visibility status of |
40 |
| - # toggable chapters module. |
41 |
| - # @option options [boolean] :timecontrolsVisible (false) Defines the default visibility status of |
42 |
| - # toggable time controls module. |
43 |
| - # @option options [boolean] :summaryVisible (false) Defines the default visibility status of |
44 |
| - # toggable summary module. |
45 |
| - # @option options [boolean] :downloadbuttonsVisible (false) Defines the default visibility of the |
46 |
| - # download buttons. |
47 |
| - # @return [String] HTML markup and JS call. |
48 |
| - def podloveaudio(options = {}) |
49 |
| - podlove("audio", options) |
50 |
| - end |
51 |
| - |
52 |
| - # Generates the HTML markup needed for the podlove video player and calls the podlovewebplayer |
53 |
| - # js method with given option parameters. |
54 |
| - # |
55 |
| - # @param [Hash] options options for the player |
56 |
| - # @option options [String] :src This location of an video file, local ore remote. |
57 |
| - # @option options [String] :type The media type of the resource. |
58 |
| - # @option options [String] :mp4 The location of an audio file with the type mp4. |
59 |
| - # @option options [String] :webm The location of an audio file with the type webm. |
60 |
| - # @option options [String] :ogg The location of an audio file with the type ogg. |
61 |
| - # @option options [String] :poster The location of the poster frame for the video. |
62 |
| - # @option options [integer] :width (auto) The width of the player. |
63 |
| - # @option options [integer] :height The height of the player. |
64 |
| - # @option options [boolean] :loop (false) Loops the video when it ends. |
65 |
| - # @option options [boolean] :preload (true) Start loading the video as soon as possible, |
66 |
| - # before the user clicks play. This might not work on all browsers. |
67 |
| - # @option options [boolean] :autoplay (false) Start playing the video as soon as it's ready. |
68 |
| - # This might not work on all (mobile) devices. |
69 |
| - # @option options [boolean] :fullscreen (true) Disables the fullscreen button for video. |
70 |
| - # @option options [string] :duration (false) Enables display of duration without having to load the |
71 |
| - # media file. Use seconds or timecode as a unit |
72 |
| - # (e.g. "3522" or "00:58:42") |
73 |
| - # @option options [boolean] :alwaysShowHours (true) Displays the time in 00:00:00 instead of 00:00. |
74 |
| - # @option options [boolean] :alwaysShowControls (true) Defines whether the player control bar is |
75 |
| - # permanently visible. It might be suitable to fade the |
76 |
| - # controls out when not hovering the video. |
77 |
| - # @option options [boolean] :volume (true) Disables the volume slider. |
78 |
| - # @option options [boolean] :progress (true) Disables the progress bar. |
79 |
| - # @option options [String] :captions URL to a WebVTT captions file. |
80 |
| - # @option options [boolean] :chapters Takes chapter string in JSON format and builds an interactive |
81 |
| - # chapter table. Chapters must be written in the following format: |
82 |
| - # !{'start':'00:00:00.000', 'title':'Chapter One', 'image':''} |
83 |
| - # @option options [String] :chapterlinks (all) Option for the jumplink behaviour in chapter table. |
84 |
| - # Options are: 'all' (all chapter links are clickable), 'buffered' (only |
85 |
| - # buffered chapters are clickable), 'false' (chapters are not linked) |
86 |
| - # @option options [boolean] :chaptersVisible (false) Defines the default visibility status of |
87 |
| - # toggable chapters module. |
88 |
| - # @option options [boolean] :timecontrolsVisible (false) Defines the default visibility status of |
89 |
| - # toggable time controls module. |
90 |
| - # @option options [boolean] :summaryVisible (false) Defines the default visibility status of |
91 |
| - # toggable summary module. |
92 |
| - # @option options [boolean] :downloadbuttonsVisible (false) Defines the default visibility of the |
93 |
| - # download buttons. |
94 |
| - # @return [String] HTML markup and JS call. |
95 |
| - def podlovevideo(options = {}) |
96 |
| - podlove("video", options) |
97 |
| - end |
98 |
| - |
99 |
| - private |
100 |
| - |
101 |
| - def podlove(type, options = {}) |
102 |
| - id = "player_" + SecureRandom.hex(5) |
103 |
| - |
104 |
| - html = "<#{type} id='#{id}'>" |
105 |
| - html << "<source src='#{options[:src]}'"\ |
106 |
| - "" + (options[:type] ? " type='#{options[:type]}'" : "") + "></source>" if options[:src] |
107 |
| - html << "<source src='#{options[:mp4]}' type='#{type}/mp4'></source>" if options[:mp4] |
108 |
| - html << "<source src='#{options[:mp3]}' type='#{type}/mpeg'></source>" if options[:mp3] |
109 |
| - html << "<source src='#{options[:ogg]}' type='#{type}/ogg; codecs=vorbis'></source>" if options[:ogg] |
110 |
| - html << "<source src='#{options[:opus]}' type='#{type}/ogg; codecs=opus'></source>" if options[:opus] |
111 |
| - html << "<source src='#{options[:webm]}' type='#{type}/webm'></source>" if options[:webm] |
112 |
| - html << "</#{type}>" |
| 1 | +module PodloveWebPlayerRails |
| 2 | + # View Helpers that generate the needed HTML and JS needed for the Web Player |
| 3 | + module ViewHelpers |
| 4 | + # Generates the HTML markup needed for the podlove audio player and calls the podlovewebplayer |
| 5 | + # js method with given option parameters. |
| 6 | + # |
| 7 | + # @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. |
| 15 | + # @option options [integer] :width (auto) The width of the player. |
| 16 | + # @option options [integer] :height The height of the player. |
| 17 | + # @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, |
| 19 | + # before the user clicks play. This might not work on all browsers. |
| 20 | + # @option options [boolean] :autoplay (false) Start playing the audio as soon as it's ready. |
| 21 | + # This might not work on all (mobile) devices. |
| 22 | + # @option options [String] :duration (false) Enables display of duration without having to load the |
| 23 | + # media file. Use seconds or timecode as a unit |
| 24 | + # (e.g. "3522" or "00:58:42") |
| 25 | + # @option options [boolean] :alwaysShowHours (true) Displays the time in 00:00:00 instead of 00:00. |
| 26 | + # @option options [boolean] :alwaysShowControls (true) Defines whether the player control bar is |
| 27 | + # permanently visible. |
| 28 | + # @option options [boolean] :volume (true) Disables the volume slider. |
| 29 | + # @option options [boolean] :progress (true) Disables the progress bar. |
| 30 | + # @option options [String] :captions URL to a WebVTT captions file. |
| 31 | + # @option options [boolean] :chapters Takes chapter string in JSON format and builds an interactive |
| 32 | + # chapter table. Chapters must be written in the following format: |
| 33 | + # !{'start':'00:00:00.000', 'title':'Chapter One', 'image':''} |
| 34 | + # @option options [String] :chapterlinks (all) Option for the jumplink behaviour in chapter table. |
| 35 | + # Options are: 'all' (all chapter links are clickable), 'buffered' (only |
| 36 | + # buffered chapters are clickable), 'false' (chapters are not linked) |
| 37 | + # @option options [boolean] :chaptersVisible (false) Defines the default visibility status of |
| 38 | + # toggable chapters module. |
| 39 | + # @option options [boolean] :timecontrolsVisible (false) Defines the default visibility status of |
| 40 | + # toggable time controls module. |
| 41 | + # @option options [boolean] :summaryVisible (false) Defines the default visibility status of |
| 42 | + # toggable summary module. |
| 43 | + # @option options [boolean] :downloadbuttonsVisible (false) Defines the default visibility of the |
| 44 | + # download buttons. |
| 45 | + # @return [String] HTML markup and JS call. |
| 46 | + def podloveaudio(options = {}) |
| 47 | + podlove("audio", options) |
| 48 | + end |
113 | 49 |
|
114 |
| - [:src, :type, :mp4, :mp3, :ogg, :opus, :webm].each{ |key| options.delete(key) } |
| 50 | + # Generates the HTML markup needed for the podlove video player and calls the podlovewebplayer |
| 51 | + # js method with given option parameters. |
| 52 | + # |
| 53 | + # @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. |
| 60 | + # @option options [integer] :width (auto) The width of the player. |
| 61 | + # @option options [integer] :height The height of the player. |
| 62 | + # @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 | + # before the user clicks play. This might not work on all browsers. |
| 65 | + # @option options [boolean] :autoplay (false) Start playing the video as soon as it's ready. |
| 66 | + # This might not work on all (mobile) devices. |
| 67 | + # @option options [boolean] :fullscreen (true) Disables the fullscreen button for video. |
| 68 | + # @option options [string] :duration (false) Enables display of duration without having to load the |
| 69 | + # media file. Use seconds or timecode as a unit |
| 70 | + # (e.g. "3522" or "00:58:42") |
| 71 | + # @option options [boolean] :alwaysShowHours (true) Displays the time in 00:00:00 instead of 00:00. |
| 72 | + # @option options [boolean] :alwaysShowControls (true) Defines whether the player control bar is |
| 73 | + # permanently visible. It might be suitable to fade the |
| 74 | + # controls out when not hovering the video. |
| 75 | + # @option options [boolean] :volume (true) Disables the volume slider. |
| 76 | + # @option options [boolean] :progress (true) Disables the progress bar. |
| 77 | + # @option options [String] :captions URL to a WebVTT captions file. |
| 78 | + # @option options [boolean] :chapters Takes chapter string in JSON format and builds an interactive |
| 79 | + # chapter table. Chapters must be written in the following format: |
| 80 | + # !{'start':'00:00:00.000', 'title':'Chapter One', 'image':''} |
| 81 | + # @option options [String] :chapterlinks (all) Option for the jumplink behaviour in chapter table. |
| 82 | + # Options are: 'all' (all chapter links are clickable), 'buffered' (only |
| 83 | + # buffered chapters are clickable), 'false' (chapters are not linked) |
| 84 | + # @option options [boolean] :chaptersVisible (false) Defines the default visibility status of |
| 85 | + # toggable chapters module. |
| 86 | + # @option options [boolean] :timecontrolsVisible (false) Defines the default visibility status of |
| 87 | + # toggable time controls module. |
| 88 | + # @option options [boolean] :summaryVisible (false) Defines the default visibility status of |
| 89 | + # toggable summary module. |
| 90 | + # @option options [boolean] :downloadbuttonsVisible (false) Defines the default visibility of the |
| 91 | + # download buttons. |
| 92 | + # @return [String] HTML markup and JS call. |
| 93 | + def podlovevideo(options = {}) |
| 94 | + podlove("video", options) |
| 95 | + end |
115 | 96 |
|
116 |
| - script = "$('##{id}').podlovewebplayer(#{options.to_json});" |
| 97 | + private |
117 | 98 |
|
118 |
| - return raw html + "\n" + javascript_tag(script) |
119 |
| - end |
120 |
| - end |
121 |
| - end |
| 99 | + def podlove(type, options = {}) |
| 100 | + id = "player_" + SecureRandom.hex(5) |
| 101 | + |
| 102 | + html = "<#{type} id='#{id}'>" |
| 103 | + html << "<source src='#{options[:src]}'"\ |
| 104 | + "" + (options[:type] ? " type='#{options[:type]}'" : "") + "></source>" if options[:src] |
| 105 | + html << "<source src='#{options[:mp4]}' type='#{type}/mp4'></source>" if options[:mp4] |
| 106 | + html << "<source src='#{options[:mp3]}' type='#{type}/mpeg'></source>" if options[:mp3] |
| 107 | + html << "<source src='#{options[:ogg]}' type='#{type}/ogg; codecs=vorbis'></source>" if options[:ogg] |
| 108 | + html << "<source src='#{options[:opus]}' type='#{type}/ogg; codecs=opus'></source>" if options[:opus] |
| 109 | + html << "<source src='#{options[:webm]}' type='#{type}/webm'></source>" if options[:webm] |
| 110 | + html << "</#{type}>" |
| 111 | + |
| 112 | + [:src, :type, :mp4, :mp3, :ogg, :opus, :webm].each{ |key| options.delete(key) } |
| 113 | + |
| 114 | + script = "$('##{id}').podlovewebplayer(#{options.to_json});" |
| 115 | + |
| 116 | + return raw html + "\n" + javascript_tag(script) |
122 | 117 | end
|
123 | 118 | end
|
124 | 119 | end
|
0 commit comments