Skip to content

Commit

Permalink
Playlist playthrough via page reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcolvar committed May 26, 2016
1 parent ce80d3f commit 9f3ea58
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
4 changes: 4 additions & 0 deletions app/assets/javascripts/avalon_player.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class AvalonPlayer
thumbnail_selector = if removeOpt('thumbnailSelector') then 'thumbnailSelector' else null
add_to_playlist = if removeOpt('addToPlaylist') then 'addToPlaylist' else null
start_time = removeOpt('startTime')
success_callback = removeOpt('success')

features = ['playpause','current','progress','duration','volume','tracks','qualities',thumbnail_selector, add_to_playlist, 'fullscreen','responsive']
features = (feature for feature in features when feature?)
Expand All @@ -38,6 +39,7 @@ class AvalonPlayer
success: (mediaElement, domObject, player) =>
@boundPrePlay = => if mejs.MediaFeatures.isAndroid then AndroidShim.androidPrePlay(this, player)
@boundPrePlay()
if success_callback then success_callback()

player_options[key] = val for key, val of opts
@player = new MediaElementPlayer element, player_options
Expand Down Expand Up @@ -95,6 +97,8 @@ class AvalonPlayer
$(@player.media).one 'loadeddata', initialize_view
keyboardAccess()
@boundPrePlay()
if @player.options.autostart
@player.media.play()

@player.load()
@setupCreationTrigger()
Expand Down
16 changes: 14 additions & 2 deletions app/views/playlists/_player.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,20 @@ Unless required by applicable law or agreed to in writing, software distributed
addToPlaylist: false,
startQuality: '<%= current_quality(@currentStreamInfo) %>',
customError: '<%= t("media_objects.player.customError").html_safe %>',
displayMediaFragment: true
})
displayMediaFragment: true,
autostart: <%= @position == 1 ? 'false' : 'true' %>,
success: function(mediaElement, domObject) {
avalonPlayer.player.media.addEventListener('timeupdate', function(e) {
if (avalonPlayer.player.getCurrentTime() > avalonPlayer.stream_info.t.split(',')[1]) {
avalonPlayer.player.media.stop();
nextUrl = $('li.now_playing').next().find('a').attr('href');
if (nextUrl) {
window.location = nextUrl;
}
}
}, false);
}
});
currentPlayer = avalonPlayer.player;
</script>
<% end %>
Expand Down
2 changes: 0 additions & 2 deletions app/views/playlists/_playlist_item.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
<li class="<%= item_class %>">
<% if item_class == 'now_playing' %>
<i class="fa fa-arrow-circle-right"></i>
<% else %>
<a href="#">
<% end %>
<%= link_to playlist_path(@playlist, position: item.position) do %>
<%= annotation.title %></a>
Expand Down
4 changes: 2 additions & 2 deletions app/views/playlists/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Unless required by applicable law or agreed to in writing, software distributed
--- END LICENSE_HEADER BLOCK ---
%>
<% @page_title = t('media_objects.show.title', :media_object_title => @playlist.title, :application_name => application_name) %>
<% position = params.has_key?(:position)? params[:position].to_i : 1 %>
<% @position = params.has_key?(:position)? params[:position].to_i : 1 %>
<div class="playlist-view container-fluid" >
<div class="container-fluid" >
<div class="row">
Expand All @@ -24,7 +24,7 @@ Unless required by applicable law or agreed to in writing, software distributed
This playlist currently has no items.
</div>
<% else %>
<% @current_playlist_item = @playlist.items.where(position: position).first %>
<% @current_playlist_item = @playlist.items.where(position: @position).first %>
<% @current_annotation = AvalonAnnotation.find(@current_playlist_item.annotation_id) %>
<% @current_masterfile = MasterFile.find(@current_playlist_item.annotation.source.split('/').last) %>
<% @current_mediaobject = MediaObject.find(@current_masterfile.mediaobject_id) %>
Expand Down

0 comments on commit 9f3ea58

Please sign in to comment.