所以我需要做簡單的應用程序,將播放音樂按下按鈕,但因爲它要求我的路徑設置爲像這樣的確切位置: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