我想用我的项目存储声音文件,以便在需要时播放,但如何使用便携式目录。 [英] i want to store a sound file with my project so it plays when i need but how do i use a portable directory.

查看:87
本文介绍了我想用我的项目存储声音文件,以便在需要时播放,但如何使用便携式目录。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以继承人的问题...........我刚创造了tic tac toe,我还在其中添加了一个声音文件........



System.Media.SoundPlayer获胜者=新的System.Media.SoundPlayer(@D:\Projects \ Tic tac toe \ Tic tac toe \bin \Debug \ win1。 wav);

winner.Play();





但该目录是导致问题的原因该目录转到其他位置,它会给出一个错误,我想把它交给几个朋友但这里的问题是那里的目录路径有所不同所以我该怎么办.........我不知道如何更好地解释它



如果(解释==坏){

please.forgive

}



plz帮助..

问候,

Ahsan Naveed

so heres the problem...........i just created tic tac toe and i also added a sound file in it like this........

System.Media.SoundPlayer winner = new System.Media.SoundPlayer(@"D:\Projects\Tic tac toe\Tic tac toe\bin\Debug\win1.wav");
winner.Play();


but the directory is the problem cause when the directory goes to some other location it will give an error i want to give it to some couple of friends but the problem here is that there directory path wouild be different so what do i do then.........i dont know how to explain it better so

if (explanation==bad){
please.forgive
}

plz help..
Regards,
Ahsan Naveed

推荐答案



使用关系路径,如下所示:



System.Media.SoundPlayer获胜者=新的System.Media.SoundPlayer(@win1.wav);

winner.Play();



这将取自wav执行(当前)目录,所以将wav文件放在与可执行文件相同的目录中。
Hi,
use a relational path instead, like this:

System.Media.SoundPlayer winner = new System.Media.SoundPlayer(@"win1.wav");
winner.Play();

This will take the wav from the executing (current) directory, so put the wav-file in the same directory as your executable.


嗨Ahsan,



如果您使用的是Windows应用程序,请将此文件另存为资源文件

作为资源添加的步骤

1.转到解决方案资源管理器中的属性

2.打开Resource.resx并单击添加资源,然后选择添加现有文件。

Hi Ahsan,

If you are using Windows Application add this file as a resource file
Steps to Add as a resource
1. Go to Properties in Solution Explorer
2. Open Resource.resx and click on add resource and then choose add existing file.
3. WindowsFormsApplication1.Properties.Resources._01___Angreji_Beat___Cocktail__128_Kbps_



获取文件名,如步骤3所示。





对于Web应用程序添加您喜欢的任何名称的文件夹.ex音乐

并将音乐文件添加到此文件夹并使用此代码获取文件。




get the the file name as in step 3.


For Web Application Add a folder whichever name you like.ex "Music"
and add music file to this folder and get file using this code.

System.IO.Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "Music\Adele-Skyfall.mp3");





现在这个完全便携。

希望这会有所帮助。



Now this totally portable.
Hope this helps.


这篇关于我想用我的项目存储声音文件,以便在需要时播放,但如何使用便携式目录。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆