public void Puase() { TemStr = ""; TemStr = TemStr.PadLeft(128, Convert.ToChar(" ")); ilong = APIClass.mciSendString("pause media", TemStr, TemStr.Length, 0); mc.State = PlayState.Puase; }
//播放 public void Play() { TemStr = ""; TemStr = TemStr.PadLeft(127, Convert.ToChar(" ")); APIClass.mciSendString("play media", TemStr, TemStr.Length, 0); mc.State = PlayState.Playing; }
//停止 public void Stop() { TemStr = ""; TemStr = TemStr.PadLeft(128, Convert.ToChar(" ")); ilong = APIClass.mciSendString("close media", TemStr, 128, 0); ilong = APIClass.mciSendString("close all", TemStr, 128, 0); mc.State = PlayState.Stop; }
//当前播放位置 public static int CurrentPosition() { string buf = ""; buf = buf.PadLeft(128, ' '); APIClass.mciSendString("status media position", buf, buf.Length, 0); buf = buf.Trim(); if (string.IsNullOrEmpty(buf)) return 0; else return (int)(Convert.ToDouble(buf)) / 1000; }
//声音控制 public static bool SetValume(int Valume) { bool result = false; string MciCommand = string.Format("setaudio media volume to {0}", Valume); int RefInt = APIClass.mciSendString(MciCommand, null, 0, 0); if (RefInt == 0) { result = true; } return result; }
//进度控制 public static bool SetProgress(int progress) { bool result = false; string MciCommand = string.Format("seek media to {0}", progress); int RefInt = APIClass.mciSendString(MciCommand, progress.ToString(), 0, 0); APIClass.mciSendString("play media", null, 0, 0); if (RefInt == 0) { result = true; } return result; }
//总时间 public static int GetMediaLength() { string durLength = ""; durLength = durLength.PadLeft(128, Convert.ToChar(" ")); APIClass.mciSendString("status media length", durLength, durLength.Length, 0); durLength = durLength.Trim(); if (string.IsNullOrEmpty(durLength)) return 0; else return Convert.ToInt32(durLength) / 1000; //int h = s / 3600; //int m = (s - (h * 3600)) / 60; //s = s - (h * 3600 + m * 60); //vReturn = string.Format("{0:D2}:{1:D2}:{2:D2}", h, m, s); }