123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- using QuartzTypeLib;
- using System;
- using System.Windows.Forms;
- namespace LYFZ.Software.MainBusiness.CallerWizard
- {
- public class Audio : Form
- {
- private const int WM_APP = 32768;
- private const int WM_GRAPHNOTIFY = 32769;
- private const int EC_COMPLETE = 1;
- private int mediaStatus;
- private double mediaDuration;
- private double mediaCurPos;
- private int mediaVolum;
- private FilgraphManager objMedia;
- private IBasicAudio volMedia;
- private IMediaControl ctlMedia;
- private IMediaPosition posMedia;
- private IMediaEventEx eexMedia;
- public int MediaStatus
- {
- get
- {
- return this.mediaStatus;
- }
- }
- public int MediaDuration
- {
- get
- {
- return (int)this.mediaDuration;
- }
- }
- public int MediaCurPos
- {
- get
- {
- if (this.posMedia != null)
- {
- this.mediaCurPos = this.posMedia.CurrentPosition;
- }
- return (int)this.mediaCurPos;
- }
- }
- public string MediaDuration2
- {
- get
- {
- return this.getLengthWithFormat((int)this.mediaDuration);
- }
- }
- public string MediaCurPos2
- {
- get
- {
- if (this.posMedia != null)
- {
- this.mediaCurPos = this.posMedia.CurrentPosition;
- }
- return this.getLengthWithFormat((int)this.mediaCurPos);
- }
- }
- public int MediaVol
- {
- get
- {
- return this.mediaVolum / 50;
- }
- set
- {
- this.mediaVolum = value * 50;
- if (this.volMedia != null)
- {
- this.volMedia.Volume = this.mediaVolum;
- }
- }
- }
- private void clearUp()
- {
- if (this.ctlMedia != null)
- {
- this.ctlMedia.Stop();
- }
- this.mediaStatus = 1;
- this.mediaDuration = 0.0;
- this.mediaCurPos = 0.0;
- if (this.eexMedia != null)
- {
- this.eexMedia.SetNotifyWindow(0, 0, 0);
- }
- if (this.ctlMedia != null)
- {
- this.ctlMedia = null;
- }
- if (this.volMedia != null)
- {
- this.volMedia = null;
- }
- if (this.posMedia != null)
- {
- this.posMedia = null;
- }
- if (this.eexMedia != null)
- {
- this.eexMedia = null;
- }
- if (this.objMedia != null)
- {
- this.objMedia = null;
- }
- }
- public void CloseMedia()
- {
- this.clearUp();
- }
- public void RenderMedia(string mediaFileName, bool run)
- {
- this.clearUp();
- try
- {
- this.objMedia = new QuartzTypeLib.FilgraphManager();
- this.objMedia.RenderFile(mediaFileName);
- this.volMedia = (this.objMedia as IBasicAudio);
- this.posMedia = (this.objMedia as IMediaPosition);
- this.ctlMedia = this.objMedia;
- this.eexMedia = (this.objMedia as IMediaEventEx);
- this.eexMedia.SetNotifyWindow((int)base.Handle, 32769, 0);
- this.mediaStatus = 1;
- this.mediaDuration = this.posMedia.Duration;
- this.volMedia.Volume = this.mediaVolum;
- if (run)
- {
- this.Play();
- }
- }
- catch
- {
- // MessageBoxCustom.Show("ÎÞ·¨ÕÒµ½²¥·ÅÎļþ!");
- return;
- //this.clearUp();
- }
- }
- public void Play()
- {
- this.ctlMedia.Run();
- this.mediaStatus = 3;
- }
- public void Pause()
- {
- this.ctlMedia.Pause();
- this.mediaStatus = 2;
- }
- public void Stop()
- {
- this.ctlMedia.Stop();
- this.posMedia.CurrentPosition = 0.0;
- this.mediaStatus = 1;
- }
- public void Seek(int posTar)
- {
- this.posMedia.CurrentPosition = (double)posTar;
- }
- protected override void WndProc(ref Message m)
- {
- if (m.Msg == 32769)
- {
- try
- {
- while (true)
- {
- int lEventCode;
- int lParam;
- int lParam2;
- this.eexMedia.GetEvent(out lEventCode, out lParam, out lParam2, 0);
- this.eexMedia.FreeEventParams(lEventCode, lParam, lParam2);
- if (lEventCode == 1)
- {
- this.ctlMedia.Stop();
- this.posMedia.CurrentPosition = 0.0;
- this.mediaStatus = 1;
- }
- }
- }
- catch (Exception)
- {
- }
- }
- base.WndProc(ref m);
- }
- private string getLengthWithFormat(int len)
- {
- int nh = len / 3600;
- int nm = (len - nh * 3600) / 60;
- int ns = len - (nh * 3600 + nm * 60);
- return string.Format("{0:D2}:{1:D2}:{2:D2}", nh, nm, ns);
- }
- }
- }
|