简体   繁体   English

如何正确播放项目中没有的音频文件

[英]How To Properly Play an Audio File That is Not in a Project

I cannot find much about this. 我对此一无所知。 My college is using JGrasp, which I think is terrible from what I have heard from people using much better IDE's. 我的大学正在使用JGrasp,从使用更好的IDE的人那里听到的消息来看,我认为这很糟糕。 My professor doesn't even use the JGrasp Project at all and makes us use .java files. 我的教授甚至根本不使用JGrasp项目,而是让我们使用.java文件。 I managed to code the program to play sound, but I have no clue where to put the file. 我设法对程序进行编码以播放声音,但是我不知道将文件放在哪里。 I have been coding in c# and used Visual Studio for 3 years now, and I never had to deal with this. 我已经在c#中进行编码,并且使用Visual Studio已有3年了,而我从来不必处理它。 I placed it in the same folder as my other .java files, since I believe files can talk that way since .java files placed in the same folder in JGrasp is able to communicate to each other. 我将其与其他.java文件放在同一文件夹中,因为我相信文件可以这样说,因为放在JGrasp中同一文件夹中的.java文件能够相互通信。 I even placed it in my c drive to see if it even detects it, but still my audio file cannot be found 我什至将它放在c驱动器中,以查看它是否能够检测到它,但是仍然找不到我的音频文件

My first attempt was to place it here C:Users/ProfileName/Desktop/Project1/sounds/Medic_cheers05.wav 我的第一次尝试是将其放置在这里C:Users / ProfileName / Desktop / Project1 / sounds / Medic_cheers05.wav

my final attempt was to place it here C:Medic_cheers05.wav 我最后的尝试是将其放置在这里C:Medic_cheers05.wav

and it doesn't work no matter where I put my audio file. 而且无论我把音频文件放在哪里都行不通。

I need help on WHERE to place the audio file. 我需要在哪里放置音频文件的帮助。 I really need help with this and it frustrates me. 我真的需要帮助,这让我感到沮丧。 Other places I checked, but they all placed it in .jar related or project related problems. 我检查了其他地方,但他们都将其置于.jar相关或项目相关的问题中。 What if you don't want to use a jar or project? 如果您不想使用jar或项目该怎么办? Can I see how this could work, if it is even possible? 如果有可能,我能看到它如何工作吗?

To be honest i have no idea. 老实说,我不知道。 But what you can try is: 但是您可以尝试的是:

"C:\\Users\\ProfileName\\Desktop\\Project1\\sounds\\Medic_cheers05.wav"

When giving the filepath. 提供文件路径时。

Keep in mind that the escape sequence \\ is not recognized usually by the IDE. 请记住,IDE通常不会识别转义序列\\ So you need to double the \\ in order to work. 因此,您需要加倍\\才能工作。
I also recommend you to always type in the full file path if the Programm is just for you. 如果程序仅适合您,我还建议您始终键入完整的文件路径。

And usually if you place the sound file in the same directory as the Java Project it should work. 通常,如果将声音文件与Java Project放在同一目录中,则它应该可以工作。

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

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