Skip to content

Commit

Permalink
Add adaptive streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
phuongdh committed Oct 21, 2020
1 parent c239641 commit 3dbd30b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/controllers/items_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ItemsController < ApplicationController
before_action :set_item, only: [:show, :edit, :update, :destroy]
before_action :set_item, only: [:show, :edit, :update, :destroy, :adaptive]
before_action :require_login, except: [:index, :authorize]

def require_login
Expand Down Expand Up @@ -81,6 +81,12 @@ def authorize
end
end

# GET /items/1/adaptive.m3u8
def adaptive
@streams = @item.streams
render layout: false, content_type: 'text/plain'
end

private
# Use callbacks to share common setup or constraints between actions.
def set_item
Expand Down
5 changes: 5 additions & 0 deletions app/views/items/adaptive.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#EXTM3U
<% @streams.each do |stream| %>
#EXT-X-STREAM-INF:BANDWIDTH=<%= stream["bitrate"] %>
<%= stream["url"] + "?token=" + session[:token]%>
<% end %>
1 change: 1 addition & 0 deletions app/views/items/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
controls
preload="auto"
>
<source src="<%= adaptive_item_path(@item, format: "m3u8") %>" type="application/x-mpegURL" label="auto"/>
<% @item.streams.each do |stream| %>
<source src="<%= stream["url"] %>?token=<%= session[:token] %>" type="application/x-mpegURL" label="<%= stream["label"] %>"/>
<% end %>
Expand Down
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
collection do
get :authorize
end
member do
match 'adaptive', to: 'items#adaptive', via: [:get]
end
end
devise_for :users
root to: "items#index"
Expand Down

0 comments on commit 3dbd30b

Please sign in to comment.