C# winfrom局域网文件复制 播放网络上的mp3文件呢?

using System.Runtime.InteropS
using System.T
using System.IO;
namespace clsMCIPlay
/// clsMci 的摘要说明。
public class clsMCI
public clsMCI()
// TODO: 在此处添加构造函数逻辑
//定义API函数使用的字符串变量
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = <span style="COLOR: #0)]
private string Name = "";
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = <span style="COLOR: #8)]
private string durLength = "";
[MarshalAs(UnmanagedType.LPTStr, SizeConst = <span style="COLOR: #8)]
private string TemStr = "";
//定义播放状态枚举变量
public enum State
mPlaying = <span style="COLOR: #,
mPuase = <span style="COLOR: #,
mStop = <span style="COLOR: #
//结构变量
public struct structMCI
public bool bM
public int iD
public int iP
public int iV
public int iB
public string iN
public structMCI mc = new structMCI();
//取得播放文件属性
public string FileName
return mc.iN
//ASCIIEncoding asc = new ASCIIEncoding();
TemStr = "";
TemStr = TemStr.PadLeft(<span style="COLOR: #7, Convert.ToChar(" "));
Name = Name.PadLeft(<span style="COLOR: #0, Convert.ToChar(" "));
mc.iName =
ilong = APIClass.GetShortPathName(
mc.iName, Name, Name.Length);
Name = GetCurrPath(Name);
//Name = "open " + Convert.ToChar(34) + Name +
Convert.ToChar(34) + " alias media";
Name = "open " + Convert.ToChar(<span style="COLOR: #) + Name +
Convert.ToChar(<span style="COLOR: #) + " alias media";
ilong = APIClass.mciSendString(
"close all", TemStr, TemStr.Length, <span style="COLOR: #);
ilong = APIClass.mciSendString(
Name, TemStr, TemStr.Length, <span style="COLOR: #);
ilong = APIClass.mciSendString(
"set media time format milliseconds",
TemStr, TemStr.Length, <span style="COLOR: #);
mc.state = State.mS
MessageBox.Show("出错错误!");
public void play()
TemStr = "";
TemStr = TemStr.PadLeft(
<span style="COLOR: #7, Convert.ToChar(" "));
APIClass.mciSendString(
"play media", TemStr, TemStr.Length, <span style="COLOR: #);
mc.state = State.mP
public void StopT()
TemStr = "";
TemStr = TemStr.PadLeft(
<span style="COLOR: #8, Convert.ToChar(" "));
ilong = APIClass.mciSendString(
"close media", TemStr, <span style="COLOR: #8, <span style="COLOR: #);
ilong = APIClass.mciSendString(
"close all", TemStr, <span style="COLOR: #8, <span style="COLOR: #);
mc.state = State.mS
public void Puase()
TemStr = "";
TemStr = TemStr.PadLeft(
<span style="COLOR: #8, Convert.ToChar(" "));
ilong = APIClass.mciSendString(
"pause media", TemStr, TemStr.Length, <span style="COLOR: #);
mc.state = State.mP
private string GetCurrPath(string name)
if (name.Length & <span style="COLOR: #) return "";
name = name.Trim();
name = name.Substring(<span style="COLOR: #, name.Length - <span style="COLOR: #);
public int Duration
durLength = "";
durLength = durLength.PadLeft(
<span style="COLOR: #8, Convert.ToChar(" "));
APIClass.mciSendString(
"status media length",
durLength, durLength.Length, <span style="COLOR: #);
durLength = durLength.Trim();
if (durLength == "") return <span style="COLOR: #;
return (int)(Convert.ToDouble(durLength) / 1000f);
//当前时间
public int CurrentPosition
durLength = "";
durLength = durLength.PadLeft(
<span style="COLOR: #8, Convert.ToChar(" "));
APIClass.mciSendString(
"status media position",
durLength, durLength.Length, <span style="COLOR: #);
mc.iPos = (int)(Convert.ToDouble(durLength) / 1000f);
return mc.iP
public class APIClass
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetShortPathName(
string lpszLongPath,
string shortFile,
int cchBuffer
[DllImport("winmm.dll", CharSet = CharSet.Auto)]
public static extern int mciSendString(
string lpstrCommand,
string lpstrReturnString,
int uReturnLength,
int hwndCallback
二、用于测试媒体播放类的简单代码:&
using System.D
using System.C
using System.ComponentM
using System.Windows.F
using System.D
using System.Runtime.InteropS
using System.T
using System.IO;
using clsMCIP
namespace MCIPlay
/// Form1 的摘要说明。
public class Form1 : Form
private IC
private Timer timer1;
private Button P
private Button S
private Button P
private Label PlayFileN
private Label D
private Label CurrentP
private OpenFileDialog openFileDialog1;
private Button BrowserF
clsMCI mp = new clsMCI();
public Form1()
// Windows 窗体设计器支持所必需的
InitializeComponent();
// TODO: 在 InitializeComponent
调用后添加任何构造函数代码
/// 清理所有正在使用的资源。
protected override void Dispose(bool disposing)
if (disposing)
if (components != null)
components.Dispose();
base.Dispose(disposing);
Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
private void InitializeComponent()
this.components = new Container();
this.Play = new Button();
this.PlayFileName = new Label();
this.Duration = new Label();
this.Stop = new Button();
this.Puase = new Button();
this.CurrentPosition = new Label();
this.timer1 = new Timer(this.components);
this.openFileDialog1 = new OpenFileDialog();
this.BrowserFile = new Button();
this.SuspendLayout();
this.Play.Location = new Point(<span style="COLOR: #2, <span style="COLOR: #3);
this.Play.Name = "Play";
this.Play.Size = new Size(<span style="COLOR: #, <span style="COLOR: #);
this.Play.TabIndex = <span style="COLOR: #;
this.Play.Text = "Play";
this.Play.Click +=
new EventHandler(this.Play_Click);
// PlayFileName
this.PlayFileName.AutoSize = true;
this.PlayFileName.Location = new Point(<span style="COLOR: #, <span style="COLOR: #);
this.PlayFileName.Name = "PlayFileName";
this.PlayFileName.Size = new Size(<span style="COLOR: #, <span style="COLOR: #);
this.PlayFileName.TabIndex = <span style="COLOR: #;
// Duration
this.Duration.AutoSize = true;
this.Duration.Location = new Point(<span style="COLOR: #, <span style="COLOR: #);
this.Duration.Name = "Duration";
this.Duration.Size = new Size(<span style="COLOR: #, <span style="COLOR: #);
this.Duration.TabIndex = <span style="COLOR: #;
this.Stop.Location = new Point(<span style="COLOR: #2, <span style="COLOR: #3);
this.Stop.Name = "Stop";
this.Stop.Size = new Size(<span style="COLOR: #, <span style="COLOR: #);
this.Stop.TabIndex = <span style="COLOR: #;
this.Stop.Text = "Stop";
this.Stop.Click +=
new EventHandler(this.Stop_Click);
this.Puase.Location = new Point(<span style="COLOR: #8, <span style="COLOR: #3);
this.Puase.Name = "Puase";
this.Puase.Size = new Size(<span style="COLOR: #, <span style="COLOR: #);
this.Puase.TabIndex = <span style="COLOR: #;
this.Puase.Text = "Puase";
this.Puase.Click +=
new EventHandler(this.Puase_Click);
// CurrentPosition
this.CurrentPosition.AutoSize = true;
this.CurrentPosition.Location = new Point(<span style="COLOR: #, <span style="COLOR: #);
this.CurrentPosition.Name = "CurrentPosition";
this.CurrentPosition.Size = new Size(<span style="COLOR: #, <span style="COLOR: #);
this.CurrentPosition.TabIndex = <span style="COLOR: #;
this.timer1.Enabled = true;
this.timer1.Interval = <span style="COLOR: #00;
this.timer1.Tick +=
new EventHandler(this.timer1_Tick);
// BrowserFile
this.BrowserFile.Location = new Point(<span style="COLOR: #2, <span style="COLOR: #5);
this.BrowserFile.Name = "BrowserFile";
this.BrowserFile.Size = new Size(<span style="COLOR: #, <span style="COLOR: #);
this.BrowserFile.TabIndex = <span style="COLOR: #;
this.BrowserFile.Text = "SelectFile";
this.BrowserFile.Click +=
new EventHandler(this.BrowserFile_Click);
this.AutoScaleBaseSize = new Size(<span style="COLOR: #, <span style="COLOR: #);
this.ClientSize = new Size(<span style="COLOR: #3, <span style="COLOR: #7);
this.Controls.Add(this.BrowserFile);
this.Controls.Add(this.CurrentPosition);
this.Controls.Add(this.Puase);
this.Controls.Add(this.Stop);
this.Controls.Add(this.Duration);
this.Controls.Add(this.PlayFileName);
this.Controls.Add(this.Play);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
#endregion
/// 应用程序的主入口点。
[STAThread]
static void Main()
Application.Run(new Form1());
//选择MP3文件播放
private void Play_Click(
object sender, System.EventArgs e)
mp.play();
MessageBox.Show("出错错误!");
//暂停播放
private void Puase_Click(
object sender, System.EventArgs e)
mp.Puase();
MessageBox.Show("出错错误!");
//停止播放
private void Stop_Click(
object sender, System.EventArgs e)
mp.StopT();
MessageBox.Show("出错错误!");
//每秒显示一次播放进度
private void timer1_Tick(
object sender, System.EventArgs e)
CurrentPosition.Text =
mp.CurrentPosition.ToString();
//浏览文件
private void BrowserFile_Click(
object sender, System.EventArgs e)
openFileDialog1.Filter = "*.mp3|*.mp3";
openFileDialog1.FileName = "";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
mp.FileName = openFileDialog1.FileN
PlayFileName.Text = openFileDialog1.FileN
Duration.Text = mp.Duration.ToString();
MessageBox.Show("出错错误!");
作者:佚名
喜欢该文的人也喜欢C# winform怎么实现mp3录音?
[问题点数:100分,结帖人20004]
C# winform怎么实现mp3录音?
[问题点数:100分,结帖人20004]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
2010年 总版技术专家分年内排行榜第一2009年 总版技术专家分年内排行榜第一
2011年 总版技术专家分年内排行榜第二
匿名用户不能发表回复!|C#中用API实现MP3等音频文件的播放类
> C#中用API实现MP3等音频文件的播放类
C#中用API实现MP3等音频文件的播放类
public void StopT() {   TemStr = ;   TemStr = TemStr.PadLeft(128,Convert.ToChar( ));   ilong = Class.mciSendString(close media, TemStr, 128, 0);   ilong = Class.mciSendString(close all, TemStr, 128, 0);   mc.state = State.mS } public void Puase() {   TemStr = ;   TemS tr = TemStr.PadLeft(128,Convert.ToChar( ));   ilong = Class.mciSendString(pause media, TemStr, TemStr.Length, 0);   mc.state = State.mP } private string GetCurrPath(string name) {   if(name.Length 1)   name = name.Trim();   name = name.Substring(0,name.Length-1);   } //总时间 public int Duration {   get   { durLength = ; durLength = durLength.PadLeft(128,Convert.ToChar( )) ; APIClass.mciSendString(status media length, durLength, durLength.Length, 0); durLength = durLength.Trim(); if(durLength == ) return 0; return (int)(Convert.ToDouble(durLength) / 1000f);   } } //当前时间 public int CurrentPosition {   get   { durLength = ; durLength = durLength.PadLeft(128,Convert.ToChar( )) ; APIClass.mciSendString(status media position, durLength, durLength.Length, 0); mc.iPos = (int)(Convert.ToDouble(durLength) / 1000f); return mc.iP   } }   }   public class APIClass   { [DllImport(kernel32.dll, CharSet = CharSet.Auto)] public static extern int GetShortPathName (   string lpszLongPath,   string shortFile,   int cchBuffer ); [DllImport(winmm.dll, EntryPoint=mciSendString, CharSet = CharSet.Auto)] public static extern int mciSendString (   string lpstrCommand,   string lpstrReturnString,   int uReturnLength,   int hwndCallback );   } }
分享给小伙伴们:
我来说两句……
微信公众号二
微信公众号一beckham88(Icanfly) 00:45:10 在 .NET技术 / C# 提问
一共三个问题: & & 1,winform里用C#怎么播放音频文件(例如:*.wav)? & & 2,C#中怎样调用api函数? & & 3,C#中怎样调用com组件?
saucer(思归)回复于
00:56:20 得分 40
1. & & http://www.codeguru.com/Csharp/Csharp/cs_graphics/sound/article.php/c6143/ & & & & http://blog.monstuff.com/archives/000070.html & & & & 2. & & & Platform & Invoke & Tutorial & & http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcwlkplatforminvoketutorial.asp & & & & http://www.pinvoke.net/ & & & & 3. & & COM & Interop & Tutorials & & http://msdn.microsoft.com/library/en-us/csref/html/vcoriCOMInteropTutorial.asp?frame=true & & & & 3
jetxia(Thinking-&Asking&Studying-&Doing)回复于
08:54:28 得分 20
1、可以调用MediaPlayer & & 2、比如 & & [DllImport("user32.dll", & EntryPoint="SetWindowLong")] & & public & static & extern & int & SetWindowLong & ( & & int & hwnd, & & int & nIndex, & & int & dwNewLong & & ); & & 3、把com组件在工程中添加引用
----------------
A Simple C# Class to Play .WAV Files in .NET
This is a simple program to test a class I wrote when I needed to play some .wav files from C#. It uses the simple Win32 command PlaySound&a throwback to earlier programming days, but it works. There are only two commands, play and stop, which are really all you need a lot of times. I wrapped it all in a simple class including the defines needed for the Play method. There is not much more to this other than it works on Win2K and WinXP and is simple to use.
One other interesting thing is I used the OpenFileDialog, a pre-configured dialog box, to get a .wav file path. It is very simple to use. Just drag it from the Toolbox to your dialog box. Watch out for the "Filter" property. The documentation says:
For each filtering option, the filter string contains a description of the filter, followed by the vertical bar (|) and the filter pattern. The strings for different filtering options are separated by the vertical bar.
The following is an example of a filter string: "Text files (*.txt)|*.txt|All files (*.*)|*.*"
You can add serveral filter patterns to a filter by separating the file types with smicolons. For example: "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*"
It's fairly easy to understand, but watch out for spaces, and that the '|' is used in two ways: to denote the actual search string extension, and to separate different search types. The dialog has several interesting functions as well. Have fun.
public class WAVSounds{
[DllImport("WinMM.dll")]
public static extern bool
PlaySound(byte[]wfname, int fuSound);
public int SND_SYNC
public int SND_ASYNC
public int SND_NODEFAULT
public int SND_MEMORY
public int SND_LOOP
public int SND_NOSTOP
public int SND_NOWAIT
public int SND_ALIAS
public int SND_ALIAS_ID
public int SND_FILENAME
public int SND_RESOURCE
public int SND_PURGE
public int SND_APPLICATION = 0x0080;
public void Play(string wfname,int SoundFlags){
byte[] bname = new Byte[256];
bname = System.Text.Encoding.ASCII.GetBytes(wfname);
PlaySound(bname,SoundFlags);}public void StopPlay(){
PlaySound(null,SND_PURGE);}}
public Form1()
InitializeComponent();
openFileDialog1.Title = "Select a Wave Sound File";
openFileDialog1.Filter = "Wav Files(*.wav)|*.wav|
All Files(*.*)|*.*";
}private void FindFileButton_Click(object sender, System.EventArgs e){
openFileDialog1.FileName = m_wav_file.T
openFileDialog1.ShowDialog();
m_wav_file.Text = openFileDialog1.FileN}private void OnPlayButtonClick(object sender, System.EventArgs e){
WAVSounds ws = new WAVSounds();
ws.Play(m_wav_file.Text,ws.SND_ASYNC);}private void StopButton_Click(object sender, System.EventArgs e){
WAVSounds ws = new WAVSounds();
ws.StopPlay();}
//文件下载: demo Project&&& Source
Minimalistic C# media player
A while back (time flies), I wrote a little media player in C#. Its main characteristic is that it is window-less. All interactions are done using the media region and a circular context menu.
The purpose of this experiment was to play with the MediaPlayer component and interop, and to try a UI-less interface design. Although all features are not yet implemented, I believe this prototype gives a good idea of the possibilities of this approach.
Interface manipulationThe media rendering region can be manipulated by drag and dropping its nine areas. Dragging the center moves the "window" around, while clicking in the periphery resizes it. The cursor changes depending on its position to reflect this behavior.Using the whole surface of the "window" to manipulate makes it more efficient, as it is hard to target the edges of regular windows to resize them.
The context menu is a set of eight buttons that appear in circle around the cursor. Their labels change depending on the state of the player. Open, Close, Quit, Play, Pause are implemented, while the Maximize, Seek, Volume and Options menus are not yet functional.Using a context menu based interface gives quick mouse or stylus access to all the features while maximizing the available surface for the media rendering.
Future workBeside implementing the missing features like Volume, Seek and Maximize, having the cursor auto-hide would be a nice addition.
The current version also has two problems:- moving and resizing isn't always fluid and synchronized with the border of the window during the manipulation,- the window's resize speed is sometimes slower than the cursor's, which leads the cursor outside of the window and the window to not receive the mouse events anymore.
The first problem occurs both when the media is paused and playing. Windows Media Player 9 has a similar behavior (on my Windows 2000 box).
The second problem is rather tricky: as soon as the cursor goes out of the window (because the window is resizing too slowly) the window stops receiving mouse events and therefore the resizing is interrupted. I believe using a system-wide hook to intercept mouse events could be a solution, although rather complex. Regular windows don't have this problem because their resizing is handled by the windows manager itself.
DownloadsBecause the MediaPlayer renders using an overlay mechanism, I couldn't take a screenshot of the running app. So you'll have to try it for yourself.Here is a , it also contains the two required interop dlls.The source is available .
Posted by Julien on June 28, 2003.
-----------
Recreated a MenuForm.resx (by copying Form1.-) and adapted the code to the new WMP10 object model.
There is one outstanding bug, which seems to come from WMP10 handling events differently when a video is running or not: when a video is running and you right click, the context menu appears and disappears instantly (instead of staying opened). Still trying to figure out a work-around.
A new zip is available at
-------&--------------
//文件下载
Views(...) Comments()在c#中如何实现MP3流的播放_百度知道
在c#中如何实现MP3流的播放
在c#中如何实现MP3流的播放,就像System.Media的SoundPlayer那样给他一个内存流,然后就可以播放(只针对wav格式的)现在我想用以上的方式播放mp3流 不要用写文件的方式 因为读取太频繁了求高手不吝赐教
没有高手在吗?提供一个方案也可以啊最好有具体的代码 谢谢了
我有更好的答案
你可以在引用中添加对系统com组件的调用,在C盘的WINDOWS的SYSTEM32目录下有一个wmp.dll文件,你在C#程序中引入这个组件,然后在程序中就可以调用这个组件了,具体的创建对象或者这个组件实现的方法baidu一下吧,我也好久不用了
采纳率:33%
DirectSound吧,SoundPlayer只能播放wav.DirectSound是DirectX的一部分,你查MSDN应该是没有吧。如果你不希望使用插件(例如各种播放器的插件),那么就需要安装DirectX的SDK,里面有相应的开发文档,网上的资源也很多。你就直接google搜DirectSound就有一大堆开发实例。
DirectSound能播放
参考资料:
为您推荐:
其他类似问题
您可能关注的内容
&#xe675;换一换
回答问题,赢新手礼包&#xe6b9;
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。}

我要回帖

更多关于 winfrom局域网文件复制 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信