同时几个文件比较麻烦一点,估计要自己写个List<string>或者别的什么来存储。你如果只想播放音频的话,看以下源码,不用感激,以前自己写的,在发霉之前贴上来。using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;namespace Joke
{
class Audio
{
//[DllImport("winmm.dll")]
//public static extern bool PlaySound(String Filename, int Mod, int Flags); //public void Play(string FileName)
//{
// PlaySound(FileName, 0, 0);
//}
[DllImport("winmm.dll")]
private static extern int mciSendString
(
string lpstrCommand,
string lpstrReturnString,
int uReturnLength,
int hwndCallback
); [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetShortPathName
(
[MarshalAs(UnmanagedType.LPTStr)] string path,
[MarshalAs(UnmanagedType.LPTStr)] StringBuilder shortPath,
int shortPathLength
); //public Audio()
//{ //} public void Play(string FileName)
{
StringBuilder shortPathTemp = new StringBuilder(255);
int result = GetShortPathName(FileName, shortPathTemp, shortPathTemp.Capacity);
string ShortPath = shortPathTemp.ToString();
mciSendString("open " + ShortPath + " alias song", "", 0, 0);
mciSendString("play song", "", 0, 0);
} //public void Stop()
//{
// mciSendString("stop song", "", 0, 0);
//} //public void Pause()
//{
// mciSendString("pause song", "", 0, 0);
//} public void Close()
{
mciSendString("close song", "", 0, 0);
}
}}
如果要放视频的话,拖控件也是可以的,不过注意一下mediaplayer的版本,不同版本有不同的用法。
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;namespace Joke
{
class Audio
{
//[DllImport("winmm.dll")]
//public static extern bool PlaySound(String Filename, int Mod, int Flags); //public void Play(string FileName)
//{
// PlaySound(FileName, 0, 0);
//}
[DllImport("winmm.dll")]
private static extern int mciSendString
(
string lpstrCommand,
string lpstrReturnString,
int uReturnLength,
int hwndCallback
); [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetShortPathName
(
[MarshalAs(UnmanagedType.LPTStr)] string path,
[MarshalAs(UnmanagedType.LPTStr)] StringBuilder shortPath,
int shortPathLength
); //public Audio()
//{ //} public void Play(string FileName)
{
StringBuilder shortPathTemp = new StringBuilder(255);
int result = GetShortPathName(FileName, shortPathTemp, shortPathTemp.Capacity);
string ShortPath = shortPathTemp.ToString();
mciSendString("open " + ShortPath + " alias song", "", 0, 0);
mciSendString("play song", "", 0, 0);
} //public void Stop()
//{
// mciSendString("stop song", "", 0, 0);
//} //public void Pause()
//{
// mciSendString("pause song", "", 0, 0);
//} public void Close()
{
mciSendString("close song", "", 0, 0);
}
}}
如果要放视频的话,拖控件也是可以的,不过注意一下mediaplayer的版本,不同版本有不同的用法。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货