mardi 24 mars 2015

Rails Webpage won't Play any Audio or Show Audio Controls

I'm developing a ruby on rails application, and would simply like there to be a button on one of my tables' show.html.erb pages that plays a single audio file. The html.erb file below will do all of this flawlessly when it's opened manually in firefox, but not when it gets called by my rails server. Instead there is no autoplay, and the button shows up but does nothing when you click it.



<!DOCTYPE html>
<html>
<head>
</head>

<button onclick="playAud()" type="button">Play</button>

<audio id = "audio" autoplay>
<source src= 'my audio.mp3' type="audio/mpeg">
</audio>

<script>
var audio = document.getElementById("audio");
function playAud() {
audio.play();
}
</script>
</body>
</html>


Also, when I add the controls command to the html audio tag, I sometimes see the controls flash briefly on the screen then disappear.


In my final html.erb I will be using a lot of controller-created variables and such, but right now I'm just trying to get this simple issue resolved. My controller's show method is all commented out at the moment.


How can I get this audio button to work?


When I go to the rails server on the console, I see this at the end of the list of actions performed:



Started GET "/phrases/my%20audio.mp3" for 127.0.0.1 at 2015-03-24 17:29:21 -0600 Processing by PhrasesController#show as Parameters: {"id"=>"my audio"} Rendered phrases/show.html.erb within layouts/application (0.9ms)



So it looks like the server is recognizing 'my audio.mp3' as a parameter it needs to "GET" for some reason... no idea why it would do that.


Aucun commentaire:

Enregistrer un commentaire