當前位置:編程學習大全網 - 源碼下載 - C# 音樂播放器怎麽弄

C# 音樂播放器怎麽弄

直接給妳個代碼吧!using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.IO;

namespace MP3File

{

public partial class frmMain : Form

{

public frmMain()

{

InitializeComponent();

}

/// <summary>

/// 瀏覽MP3文件

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btn_Open_Click(object sender, EventArgs e)

{

if (this.oFDlog_Info.ShowDialog() == DialogResult.OK)

{

this.lV_Info.Items.Clear();

string[] FileNames = this.oFDlog_Info.FileNames;

foreach (string FileName in FileNames)

{

//取得文件大小

FileInfo FileInfo = new FileInfo(FileName);

float FileSize = (float)FileInfo.Length / (1024 * 1024);

this.axMP_Info.FileName = FileName;

//取得作者信息

string Author = this.axMP_Info.GetMediaInfoString(MediaPlayer.MPMediaInfoType.mpClipAuthor);

//取得不含路徑的文件名

string ShortFileName = FileName.Substring(FileName.LastIndexOf("\\") + 1);

ShortFileName = ShortFileName.Substring(0, ShortFileName.Length - 4);

//填充歌曲列表

string[] SubItem ={ ShortFileName, Author, FileSize.ToString().Substring(0, 4) + "M", FileName };

ListViewItem Item = new ListViewItem(SubItem);

this.lV_Info.Items.Add(Item);

this.lV_Info.Items[0].Selected = true;

}

}

}

/// <summary>

/// 播放MP3文件

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btn_Play_Click(object sender, EventArgs e)

{

if (this.lV_Info.Items.Count > 0)

{

if (this.lV_Info.SelectedItems.Count > 0)

{

int iPos = this.lV_Info.SelectedItems[0].Index;

string FileName = this.lV_Info.Items[iPos].SubItems[3].Text.ToString();

this.axMP_Info.FileName = FileName;

this.axMP_Info.Play();

}

}

else

{

MessageBox.Show("請選擇歌曲!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

}

/// <summary>

/// 暫停播放

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btn_Pase_Click(object sender, EventArgs e)

{

if (this.axMP_Info.FileName.Length > 0)

this.axMP_Info.Pause();

else

{

MessageBox.Show("請選擇歌曲!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

}

/// <summary>

/// 上壹首歌曲

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btn_Pre_Click(object sender, EventArgs e)

{

if (this.lV_Info.Items.Count > 0)

{

if (this.lV_Info.SelectedItems.Count > 0)

{

int iPos = this.lV_Info.SelectedItems[0].Index;

if (iPos > 0)

{

this.lV_Info.Items[iPos - 1].Selected = true;

string FileName = this.lV_Info.Items[iPos - 1].SubItems[3].Text.ToString();

this.axMP_Info.FileName = FileName;

this.axMP_Info.Play();

}

else

{

MessageBox.Show("已經是第壹首歌曲!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

}

}

else

{

MessageBox.Show("請選擇歌曲!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

}

/// <summary>

/// 下壹首歌曲

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btn_Next_Click(object sender, EventArgs e)

{

if (this.lV_Info.Items.Count > 0)

{

if (this.lV_Info.SelectedItems.Count > 0)

{

int iPos = this.lV_Info.SelectedItems[0].Index;

if (iPos < this.lV_Info.Items.Count - 1)

{

this.lV_Info.Items[iPos + 1].Selected = true;

string FileName = this.lV_Info.Items[iPos + 1].SubItems[3].Text.ToString();

this.axMP_Info.FileName = FileName;

this.axMP_Info.Play();

}

else

{

MessageBox.Show("已經是最後壹首歌曲!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

}

}

else

{

MessageBox.Show("請選擇歌曲!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

}

/// <summary>

/// 停止播放

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btn_Stop_Click(object sender, EventArgs e)

{

if (this.axMP_Info.FileName.Length > 0)

this.axMP_Info.Stop();

else

{

MessageBox.Show("請選擇歌曲!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

}

}

}

詳細情況 可以留言!

  • 上一篇:梅捷amd940主板 顯示器無顯示,診斷卡跑停在7f 7e處這是什麽問題
  • 下一篇:怎麽看自己淘寶賬號?
  • copyright 2024編程學習大全網