using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Media;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
SoundPlayer player1 = new SoundPlayer("cishi.wav");
player1.Play();
}
}
}
这种方法只适用于wav格式的。
后我读取mp3格式的我是这样读取的:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Media;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
WMPLib.WindowsMediaPlayer wmp = new WMPLib.WindowsMediaPlayer();
wmp.URL = "mp3cishi.mp3";
wmp.controls.play();
}
}
}
在此中引用Interop.WMPLib.dll这个组件。这个是可以读取,但在杀毒软件的检测下,它是有漏洞的,检测为蠕虫病毒。
希望大家能有好的建议,好的其它方法帮我解决这个问题(C# WinForm 窗体程序如何调用mp3格式的音频文件),在此谢谢了。
11 个解决方案
#1
窗口里拉一AxWindowsMediaPlayer控件来播放
#2
调用windows自带的播放器撒
#3
你好,你说用AxWindowsMediaPlayer控件来播放,能否详解一下,由于我没用过,谢了,,,
#4
工具箱里右键 选择项,在COM 选 加WINDOWS MADIA PLAYER 控件然后放到窗体中
WMPLib.IWMPMedia a = axWindowsMediaPlayer1.newMedia("E:\\981da8.MP3");
axWindowsMediaPlayer1.currentPlaylist.appendItem(a);
axWindowsMediaPlayer1.Ctlcontrols.play();//播放
axWindowsMediaPlayer1.settings.setMode("loop", true);//循环播放
axWindowsMediaPlayer1.Ctlcontrols.stop();//停止
WMPLib.IWMPMedia a = axWindowsMediaPlayer1.newMedia("E:\\981da8.MP3");
axWindowsMediaPlayer1.currentPlaylist.appendItem(a);
axWindowsMediaPlayer1.Ctlcontrols.play();//播放
axWindowsMediaPlayer1.settings.setMode("loop", true);//循环播放
axWindowsMediaPlayer1.Ctlcontrols.stop();//停止
#5
你好,刚我按你的方法试了一下,是可以播放的,但不知道你打好包后,变成.exe程序后,在杀毒软件的检测下是否会有漏洞,因为这个也是调用系统自带的播放器,组件。谢了,,,
#6
你什么时候杀毒软件?
#7
#region 播放Mp3
public class Mp3Player
{
// <summary>
/// 使用API
/// </summary>
static uint SND_ASYNC = 0x0001; // play asynchronously
static uint SND_FILENAME = 0x00020000; // name is file name
[DllImport("winmm.dll")]
static extern int mciSendString(string m_strCmd, string m_strReceive, int m_v1, int m_v2);
[DllImport("Kernel32", CharSet = CharSet.Auto)]
static extern Int32 GetShortPathName(String path,StringBuilder shortPath, Int32 shortPathLength);
public static void Play(string MusicFile)
{
if (!System.IO.File.Exists(MusicFile)) return;
StringBuilder shortpath=new StringBuilder(80);
int result = GetShortPathName(MusicFile, shortpath, shortpath.Capacity);
MusicFile = shortpath.ToString();
mciSendString(@"close all",null,0,0);
mciSendString(@"open " + MusicFile + " alias song", null, 0, 0); //打开
mciSendString("play song",null,0,0); //播放
}
}
#endregion
public class Mp3Player
{
// <summary>
/// 使用API
/// </summary>
static uint SND_ASYNC = 0x0001; // play asynchronously
static uint SND_FILENAME = 0x00020000; // name is file name
[DllImport("winmm.dll")]
static extern int mciSendString(string m_strCmd, string m_strReceive, int m_v1, int m_v2);
[DllImport("Kernel32", CharSet = CharSet.Auto)]
static extern Int32 GetShortPathName(String path,StringBuilder shortPath, Int32 shortPathLength);
public static void Play(string MusicFile)
{
if (!System.IO.File.Exists(MusicFile)) return;
StringBuilder shortpath=new StringBuilder(80);
int result = GetShortPathName(MusicFile, shortpath, shortpath.Capacity);
MusicFile = shortpath.ToString();
mciSendString(@"close all",null,0,0);
mciSendString(@"open " + MusicFile + " alias song", null, 0, 0); //打开
mciSendString("play song",null,0,0); //播放
}
}
#endregion
#8
调用Windows自带的播放器不就行了吗?可以把播放器组件复制后放在Debug文件下,运行后就行了
#9
先感谢各位的帮助。你好,调用Windows自带的播放器,调用方法,要复制哪些组件放在Debug文件下,能否详解一下,谢了,,,
#10
我试了7楼 那位兄弟给的:
#region 播放Mp3
public class Mp3Player
{
// <summary>
/// 使用API
/// </summary>
static uint SND_ASYNC = 0x0001; // play asynchronously
static uint SND_FILENAME = 0x00020000; // name is file name
[DllImport("winmm.dll")]
static extern int mciSendString(string m_strCmd, string m_strReceive, int m_v1, int m_v2);
[DllImport("Kernel32", CharSet = CharSet.Auto)]
static extern Int32 GetShortPathName(String path,StringBuilder shortPath, Int32 shortPathLength);
public static void Play(string MusicFile)
{
if (!System.IO.File.Exists(MusicFile)) return;
StringBuilder shortpath=new StringBuilder(80);
int result = GetShortPathName(MusicFile, shortpath, shortpath.Capacity);
MusicFile = shortpath.ToString();
mciSendString(@"close all",null,0,0);
mciSendString(@"open " + MusicFile + " alias song", null, 0, 0); //打开
mciSendString("play song",null,0,0); //播放
}
}
#endregion
这个方法是可以的,谢了,请问各位哪种方法要好一些,,,
#region 播放Mp3
public class Mp3Player
{
// <summary>
/// 使用API
/// </summary>
static uint SND_ASYNC = 0x0001; // play asynchronously
static uint SND_FILENAME = 0x00020000; // name is file name
[DllImport("winmm.dll")]
static extern int mciSendString(string m_strCmd, string m_strReceive, int m_v1, int m_v2);
[DllImport("Kernel32", CharSet = CharSet.Auto)]
static extern Int32 GetShortPathName(String path,StringBuilder shortPath, Int32 shortPathLength);
public static void Play(string MusicFile)
{
if (!System.IO.File.Exists(MusicFile)) return;
StringBuilder shortpath=new StringBuilder(80);
int result = GetShortPathName(MusicFile, shortpath, shortpath.Capacity);
MusicFile = shortpath.ToString();
mciSendString(@"close all",null,0,0);
mciSendString(@"open " + MusicFile + " alias song", null, 0, 0); //打开
mciSendString("play song",null,0,0); //播放
}
}
#endregion
这个方法是可以的,谢了,请问各位哪种方法要好一些,,,
#11
还是我这个方法好呀。
#1
窗口里拉一AxWindowsMediaPlayer控件来播放
#2
调用windows自带的播放器撒
#3
你好,你说用AxWindowsMediaPlayer控件来播放,能否详解一下,由于我没用过,谢了,,,
#4
工具箱里右键 选择项,在COM 选 加WINDOWS MADIA PLAYER 控件然后放到窗体中
WMPLib.IWMPMedia a = axWindowsMediaPlayer1.newMedia("E:\\981da8.MP3");
axWindowsMediaPlayer1.currentPlaylist.appendItem(a);
axWindowsMediaPlayer1.Ctlcontrols.play();//播放
axWindowsMediaPlayer1.settings.setMode("loop", true);//循环播放
axWindowsMediaPlayer1.Ctlcontrols.stop();//停止
WMPLib.IWMPMedia a = axWindowsMediaPlayer1.newMedia("E:\\981da8.MP3");
axWindowsMediaPlayer1.currentPlaylist.appendItem(a);
axWindowsMediaPlayer1.Ctlcontrols.play();//播放
axWindowsMediaPlayer1.settings.setMode("loop", true);//循环播放
axWindowsMediaPlayer1.Ctlcontrols.stop();//停止
#5
你好,刚我按你的方法试了一下,是可以播放的,但不知道你打好包后,变成.exe程序后,在杀毒软件的检测下是否会有漏洞,因为这个也是调用系统自带的播放器,组件。谢了,,,
#6
你什么时候杀毒软件?
#7
#region 播放Mp3
public class Mp3Player
{
// <summary>
/// 使用API
/// </summary>
static uint SND_ASYNC = 0x0001; // play asynchronously
static uint SND_FILENAME = 0x00020000; // name is file name
[DllImport("winmm.dll")]
static extern int mciSendString(string m_strCmd, string m_strReceive, int m_v1, int m_v2);
[DllImport("Kernel32", CharSet = CharSet.Auto)]
static extern Int32 GetShortPathName(String path,StringBuilder shortPath, Int32 shortPathLength);
public static void Play(string MusicFile)
{
if (!System.IO.File.Exists(MusicFile)) return;
StringBuilder shortpath=new StringBuilder(80);
int result = GetShortPathName(MusicFile, shortpath, shortpath.Capacity);
MusicFile = shortpath.ToString();
mciSendString(@"close all",null,0,0);
mciSendString(@"open " + MusicFile + " alias song", null, 0, 0); //打开
mciSendString("play song",null,0,0); //播放
}
}
#endregion
public class Mp3Player
{
// <summary>
/// 使用API
/// </summary>
static uint SND_ASYNC = 0x0001; // play asynchronously
static uint SND_FILENAME = 0x00020000; // name is file name
[DllImport("winmm.dll")]
static extern int mciSendString(string m_strCmd, string m_strReceive, int m_v1, int m_v2);
[DllImport("Kernel32", CharSet = CharSet.Auto)]
static extern Int32 GetShortPathName(String path,StringBuilder shortPath, Int32 shortPathLength);
public static void Play(string MusicFile)
{
if (!System.IO.File.Exists(MusicFile)) return;
StringBuilder shortpath=new StringBuilder(80);
int result = GetShortPathName(MusicFile, shortpath, shortpath.Capacity);
MusicFile = shortpath.ToString();
mciSendString(@"close all",null,0,0);
mciSendString(@"open " + MusicFile + " alias song", null, 0, 0); //打开
mciSendString("play song",null,0,0); //播放
}
}
#endregion
#8
调用Windows自带的播放器不就行了吗?可以把播放器组件复制后放在Debug文件下,运行后就行了
#9
先感谢各位的帮助。你好,调用Windows自带的播放器,调用方法,要复制哪些组件放在Debug文件下,能否详解一下,谢了,,,
#10
我试了7楼 那位兄弟给的:
#region 播放Mp3
public class Mp3Player
{
// <summary>
/// 使用API
/// </summary>
static uint SND_ASYNC = 0x0001; // play asynchronously
static uint SND_FILENAME = 0x00020000; // name is file name
[DllImport("winmm.dll")]
static extern int mciSendString(string m_strCmd, string m_strReceive, int m_v1, int m_v2);
[DllImport("Kernel32", CharSet = CharSet.Auto)]
static extern Int32 GetShortPathName(String path,StringBuilder shortPath, Int32 shortPathLength);
public static void Play(string MusicFile)
{
if (!System.IO.File.Exists(MusicFile)) return;
StringBuilder shortpath=new StringBuilder(80);
int result = GetShortPathName(MusicFile, shortpath, shortpath.Capacity);
MusicFile = shortpath.ToString();
mciSendString(@"close all",null,0,0);
mciSendString(@"open " + MusicFile + " alias song", null, 0, 0); //打开
mciSendString("play song",null,0,0); //播放
}
}
#endregion
这个方法是可以的,谢了,请问各位哪种方法要好一些,,,
#region 播放Mp3
public class Mp3Player
{
// <summary>
/// 使用API
/// </summary>
static uint SND_ASYNC = 0x0001; // play asynchronously
static uint SND_FILENAME = 0x00020000; // name is file name
[DllImport("winmm.dll")]
static extern int mciSendString(string m_strCmd, string m_strReceive, int m_v1, int m_v2);
[DllImport("Kernel32", CharSet = CharSet.Auto)]
static extern Int32 GetShortPathName(String path,StringBuilder shortPath, Int32 shortPathLength);
public static void Play(string MusicFile)
{
if (!System.IO.File.Exists(MusicFile)) return;
StringBuilder shortpath=new StringBuilder(80);
int result = GetShortPathName(MusicFile, shortpath, shortpath.Capacity);
MusicFile = shortpath.ToString();
mciSendString(@"close all",null,0,0);
mciSendString(@"open " + MusicFile + " alias song", null, 0, 0); //打开
mciSendString("play song",null,0,0); //播放
}
}
#endregion
这个方法是可以的,谢了,请问各位哪种方法要好一些,,,
#11
还是我这个方法好呀。