简体   繁体   English

在浏览器中播放MP3

[英]Play MP3 in browser

I'm trying to allow a user on my site to click a button and via an ajax call load an mp3 file that is created on the server to their browser and then begin playing that file. 我试图让我网站上的用户单击一个按钮,并通过ajax调用将在服务器上创建的mp3文件加载到他们的浏览器,然后开始播放该文件。 The file cannot be publicly accessible sense it contains user account specific information. 该文件不能公开访问,因为它包含用户帐户特定的信息。 So, I've created the server side code that creates the mp3 but I do not know how to stream the file to the browser from my controller. 因此,我创建了创建mp3的服务器端代码,但是我不知道如何从控制器将文件流式传输到浏览器。 Here is my current controller method. 这是我当前的控制器方法。

def play_mp3
    t = TextToSpeech.new(current_user, "Play this text in the saved mp3 file")
    mp3_file = t.text_to_speech
end

<audio autoplay controls="controls">
<source src="/YOURMP3FILE.mp3" />
</audio>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM