Skip to content

Commit

Permalink
Add Audio viewer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Trey Terrell committed Jul 15, 2014
1 parent 4ac2cc2 commit 3dede92
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
17 changes: 17 additions & 0 deletions app/decorators/audio_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class AudioDecorator < GenericAssetDecorator
def view_partial
"audio_viewer"
end

def audio_files
ogg_file.merge(mp3_file)
end

def ogg_file
{"application/ogg" => "/media/audio/"+Pathname.new(ogg_location.to_s).relative_path_from(object.send(:audio_base_path)).to_s}
end

def mp3_file
{"audio/mpeg" => "/media/audio/"+Pathname.new(mp3_location.to_s).relative_path_from(object.send(:audio_base_path)).to_s}
end
end
4 changes: 2 additions & 2 deletions app/models/audio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def create_ogg
}, :processor => :audio_filesystem
end

private
protected

def audio_location
fd = OregonDigital::FileDistributor.new(pid)
Expand All @@ -39,7 +39,7 @@ def audio_location
end

def audio_base_path
return APP_CONFIG.try(:thumbnail_path) || Rails.root.join("media", "audio")
return APP_CONFIG.try(:audio_path) || Rails.root.join("media", "audio")
end

end
5 changes: 5 additions & 0 deletions app/views/catalog/_audio_viewer.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<audio controls>
<% decorated_object.audio_files.each do |mime,file| %>
<source src="<%= file %>" type="<%= mime %>">
<% end %>
</audio>
7 changes: 7 additions & 0 deletions spec/features/asset_viewer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@
click_link "Generic thingy"
expect(page).to have_selector("#generic-viewer")
end

it "should use the audio viewer for audio files" do
FactoryGirl.create(:audio, :with_audio_datastream, :title => "Test Audio")
click_button "search"
click_link "Test Audio"
expect(page).to have_selector("audio")
end
end

0 comments on commit 3dede92

Please sign in to comment.