当前位置:编程学习 > C#/ASP.NET >>

C# WinForm 窗体程序如何调用mp3格式的音频文件

读取wav格式的我是这样读取的:
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这个组件。这个是可以读取,但在杀毒软件的检测下,它是有漏洞的,检测为蠕虫病毒。


后我又用了这种方法
#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
但这种方法调用时,为何有些MP3格式的音频文件无法读取。
望大家能有好的建议,好的其它方法帮我解决这个问题(C# WinForm 窗体程序如何调用mp3格式的音频文件),在此谢谢了。 --------------------编程问答-------------------- 这个问题没研究过。帮你顶贴增加人气………………………………………… --------------------编程问答-------------------- http://hi.baidu.com/lc761226/blog/item/44a459d96cc6b46dd0164edd.html --------------------编程问答-------------------- 帮你顶下了,没做过  --------------------编程问答-------------------- http://zhidao.baidu.com/question/80914519
C#的winform程序如何实现mp3文件的播放 --------------------编程问答-------------------- 先谢谢各位的帮助:
试了2楼给的:
http://hi.baidu.com/lc761226/blog/item/44a459d96cc6b46dd0164edd.html 
给的用axWindowsMediaPlayer方法是可以播放的,
也试了4楼给的:http://zhidao.baidu.com/question/80914519
用API函数,但不知有些MP3格式的音频文件无法读取。
请问各位:不知用哪种方法最好,或有不同的建议。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,