Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,16 @@ class filter_jwplayer_media extends core_media_player {
* @param int $height Optional height; 0 to use default
* @param array $options Options array
* subtitles
* use 'subtitles' key with an array of subtitle track files
* use 'subtitles' key with an array of moodle_url to subtitle track files
* in vtt or srt format indexed by label name.
* Example: $options['subtitles']['English'] = http://example.com/english.vtt
* use 'chapters' or 'thumbnail' index for adding chapters/thumbnails
* to the video. see:
* * http://support.jwplayer.com/customer/portal/articles/1407438-adding-closed-captions
* * http://support.jwplayer.com/customer/portal/articles/1407454-adding-chapter-markers
* * http://support.jwplayer.com/customer/portal/articles/1407439-adding-preview-thumbnails
* Examples:
* $options['subtitles']['English'] = new moodle_url('english.vtt')
* $options['subtitles']['chapters'] = new moodle_url('chapters.vtt')
* @return string HTML code for embed
*/
public function embed($urls, $name, $width, $height, $options) {
Expand Down Expand Up @@ -161,9 +168,15 @@ public function embed($urls, $name, $width, $height, $options) {
if (isset($options['subtitles'])) {
$tracks = array();
foreach ($options['subtitles'] as $label => $subtitlefileurl) {
$tracks[] = array(
'file' => $subtitlefileurl->out(),
'label' => $label);
if ($label == 'chapters' || $label == 'thumbnails') {
$tracks[] = array(
'file' => $subtitlefileurl->out(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be better as "->out(false)" to prevent the URLs being escaped which causes issues if the URL contains a query string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the URL will be embedded in the Javascript code we need the unescaped version. Otherwise jwplayer could not parse the html escaped URL.

You dropped the subtitle feature by adding the if statement.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that was my point.

By default the out method for a moodle_url has escaped set to true, so this needs to specify false to ensure we're using the unescaped version.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which if statement are you referring to?

The only one there appears to check $options['subtitles'] is set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I misunderstood you. Maybe I should not work just from my smartphone. You are right and I will change this as soon I'm back in office.

'kind' => $label);
} else {
$tracks[] = array(
'file' => $subtitlefileurl->out(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise would be better as "->out(false)"

'label' => $label);
}
}
$playlistitem['tracks'] = $tracks;
}
Expand Down