所以我需要做简单的应用程序,将播放音乐按下按钮,但因为它要求我的路径设置为像这样的确切位置:player.SoundLocation = @“C:\用户\艾娃\桌面\新建文件夹(6)\ music.wav“;它只适用于我的电脑,所以如何使它可以在其他电脑上运行?没有确切的音乐文件位置?如果我想在其他电脑上使用应用程序,在哪里存储音乐文件?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace songs
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
if(button1.Text=="stop")
{
player.Stop();
{
button1.Text = "play";
}
}
else
{
player.SoundLocation = @"C:\Users\Ava\Desktop\New folder (6)\music.wav";
player.Load();
button1.Text = "stop";
player.PlayLooping();
}
}
}
}
可以将您提供您究竟怎么回事这个例子吗?就目前而言,其答案只是使用相对路径而不是绝对路径。 – Eddge
的可能的复制[如何获得Windows中的当前用户的主目录(http://stackoverflow.com/questions/9542611/how-to-get-the-current-users-home-directory-in-windows)。编辑:[本](http://stackoverflow.com/questions/1143706/getting-the-path-of-the-home-directory-in-c)是一个更好的例子。 –
@Avadoto使用代码语法添加到您的问题。 – Eddge