public class Player : MonoBehaviour {
//中文字体
public GUISkin ChineseSkin;
//音频文件
public AudioSource[] MyAudio;
//歌曲名称
public string[] SongNames;
//当前歌曲编号
public string[] SongerNames;
//当前歌曲编号
int SongIndex = 0;
//设定是否循环
bool LoopPlay = true;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI()
{
GUI.skin = ChineseSkin;
if (GUI.Button(new Rect(10,10,50,30),"开始"))
{
MyAudio[SongIndex].Play();
}
if (GUI.Button(new Rect(70,10,50,30),"暂停"))
{
MyAudio[SongIndex].Pause();
}
if (GUI.Button(new Rect(130,10,50,30),"停止"))
{
MyAudio[SongIndex].Stop();
}
if (GUI.Button(new Rect(190,10,60,30),"上一首"))
{
///方法一: 停止播放当前音乐
//for (int i = 0; i < MyAudio.Length; i++)
//{
// if (MyAudio[i].isPlaying)
// {
// MyAudio[i].Stop();
// }
//}
//方法二:停止当前播放音乐
if (MyAudio[SongIndex].isPlaying)
{
MyAudio[SongIndex].Stop();
}
//上一曲
if (SongIndex>0)
SongIndex--;
else if(LoopPlay)
SongIndex = MyAudio.Length - 1;
//播放当前音乐
MyAudio[SongIndex].Play();
}
if (GUI.Button(new Rect(260, 10, 60, 30), "下一首"))
{
//方法一: 停止播放当前音乐
//for (int i = 0; i < MyAudio.Length; i++)
//{
// if (MyAudio[i].isPlaying)
// {
// MyAudio[i].Stop();
// }
//}
//方法二:停止当前播放音乐
if (MyAudio[SongIndex].isPlaying)
{
MyAudio[SongIndex].Stop();
}