简体   繁体   English

我的Web应用程序用户如何单击按钮以播放本地存储的mp3文件?

[英]How can my web app user click a button to play a locally stored mp3 file?

I'd like to allow my users to click a button in a list of tunes on a page to open a simple mp3 player (the HTML5 Player is fine) that can play a downloaded mp3 track for that song that is stored on the user's hard drive. 我想允许我的用户单击页面上的乐曲列表中的一个按钮,以打开一个简单的mp3播放器(HTML5播放器就可以了),该播放器可以播放用户硬盘上存储的该歌曲的下载的mp3曲目驾驶。 Is that even possible? 那有可能吗? Every attempt I've tried - using HTML and/or JS, JQ - fails. 我尝试过的每一次尝试-使用HTML和/或JS,JQ-均失败。

I can copy the local mp3 file path/filename into my Chrome address bar. 我可以将本地mp3文件的路径/文件名复制到Chrome地址栏中。 With no code at all it helpfully opens an HTML5 player in a new tab that allows me to play the tune just fine. 完全没有任何代码,它可以在新选项卡中帮助打开HTML5播放器,让我可以很好地播放音乐。 Why is it so difficult to allow the user to do the same thing by simply clicking a button inside my app? 为什么仅通过单击我的应用程序内的按钮来允许用户执行相同的操作如此困难?

I have been able to get an mp3 player to appear on the page. 我已经能够使mp3播放器出现在页面上。 But no matter how I specify the file path it refuses to play the tune - occasionally telling me my code is not allowed to access local files. 但是,无论我如何指定文件路径,它都会拒绝播放声音-偶尔告诉我,我的代码不允许访问本地文件。

For security reasons, Javascript does not have the privilege to modify files, or even open files on the client machine. 出于安全原因,Javascript没有权限修改文件,甚至没有权限在客户端计算机上打开文件。 If that is absolutely what you want to accomplish, try to use a JAVA Applet. 如果那绝对是您想要实现的目标,请尝试使用JAVA Applet。

Thanks Lyes Ben. 感谢Lyes Ben。 Over the last few days thinking about your comments has helped me understand that what I was attempting was not the right approach - and why. 在过去的几天中,思考您的评论已帮助我了解,我所尝试的方法不是正确的方法-以及原因。 After some research I now believe that using the DropBox api I can code a simple 'drop-in-saver' function that would not only automatically save the files locally that my user would generate through the app, but would at the same time, provide another feature that was on my list - it would give the user offline access to those files. 经过一番研究,我现在相信我可以使用DropBox api编写一个简单的“ drop-in-saver”功能,该功能不仅会自动将用户通过应用程序生成的文件本地保存到本地,而且还将提供我列表中的另一个功能-它可以使用户脱机访问这些文件。 As a bonus the files would be synced on all the user's devices, with no additional code or complexity in the app. 作为奖励,这些文件将在所有用户的设备上同步,而无需在应用程序中添加任何代码或复杂性。

Sometimes I get so focused on solving a particular technical problem that I fail to step back and ask if it is the right problem to solve in the first place. 有时,我过于专注于解决特定的技术问题,以至于我没有退后一步,一开始就问这是否是正确的问题。

It's not done yet but I'm now working on that DropBox interface to my app. 还没有完成,但是我现在正在使用我的应用程序的DropBox界面。 I'll update this answer when (if) I get there as I suspect this could be a solution in some cases for others facing a similar problem. 当(如果)到达那里时,我会更新此答案,因为我怀疑这在某些情况下可能是解决其他面临类似问题的解决方案。

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

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