class MediaInfo { public string FileName { get; set; } public bool PlayState { get; set; } } public class test { List<MediaInfo> MediaFile = new List<MediaInfo>(); System.Timers.Timer avilbeMediaChecher; public test() { avilbeMediaChecher = new System.Timers.Timer(5000); avilbeMediaChecher.Elapsed += avilbeMediaChecher_Elapsed; avilbeMediaChecher.Start(); } //this method calls from another thread when an event ocuring public void AddMedia(MediaInfo info) { MediaFile.Add(info); } //this method calls form another thread when an event ocuring public void Remove(MediaInfo info) { MediaFile.Remove(info); } void avilbeMediaChecher_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { try { foreach (var item in MediaFile) { if (!item.PlayState) { var idx = MediaFile.FindIndex(f => f == item); item.PlayState = true; MediaFile[idx] = item; Play(item); } } } catch (InvalidOperationException) { } } private void Play(MediaInfo item) { WindowsMediaPlayer wmp = new WindowsMediaPlayer(); wmp.PlayStateChange += wmp_PlayStateChange; wmp.currentPlaylist.clear(); wmp.currentPlaylist.appendItem(wmp.newMedia(Environment.CurrentDirectory + @"\sound\1.wma")); wmp.currentPlaylist.appendItem(wmp.newMedia(item.FileName.Trim())); wmp.currentPlaylist.appendItem(wmp.newMedia(Environment.CurrentDirectory + @"\sound\2.wma")); wmp.controls.play(); avilbeMediaChecher.Stop(); } int palayedCount = 1; private void wmp_PlayStateChange(int NewState) { if (NewState == (int)WMPLib.WMPPlayState.wmppsMediaEnded) palayedCount++; if (NewState == (int)WMPLib.WMPPlayState.wmppsMediaEnded && palayedCount == 3) { palayedCount = 1; avilbeMediaChecher.Start(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)