private void InitMusicWindow() { if (playMusicWindow == null) { PlayMusicWindowViewModel playMusicVM = new PlayMusicWindowViewModel(); playMusicWindow = new PlayMusicWindow(playMusicVM); playMusicWindow.StateChanged += playMusicWindow_StateChanged; playMusicWindow.Closed += playMusicWindow_Closed; } }
private void SynchronizePlayStatus() { Dispatcher.BeginInvoke((Action)(() => { PlayMusicWindowViewModel vm = DataContext as PlayMusicWindowViewModel; MusicStatus musicStatus = vm.RoomWindowVM.RoomClient.GetMusicStatus(vm.RoomWindowVM.RoomVM.Id); if (musicStatus != null) //someone is playing music { //ask server to get latest play status vm.RoomWindowVM.RoomClient.RequestMusicStatus(vm.RoomWindowVM.RoomVM.Id, vm.Me.Id); } })); }
public void Dispose() { Dispatcher.BeginInvoke((Action)(() => { PlayMusicWindowViewModel vm = DataContext as PlayMusicWindowViewModel; if (vm != null) { vm.RoomWindowVM.RoomCallback.StartMusicEvent -= RoomCallback_StartMusicEvent; vm.RoomWindowVM.RoomCallback.TogglePauseMusicEvent -= RoomCallback_TogglePauseMusicEvent; vm.RoomWindowVM.RoomCallback.SetMusicVolumeEvent -= RoomCallback_SetMusicVolumeEvent; vm.RoomWindowVM.RoomCallback.SetPlayPositionEvent -= RoomCallback_SetPlayPositionEvent; vm.RoomWindowVM.RoomCallback.ReportMusicStatusEvent -= RoomCallback_ReportMusicStatusEvent; vm.RoomWindowVM.RoomCallback.UpdateMusicStatusEvent -= RoomCallback_UpdateMusicStatusEvent; } })); flex.Dispose(); }
public PlayMusicWindow(PlayMusicWindowViewModel vm) : base(vm) { MinHeight = ActualHeight;//overide the MiniHeight set by window base MaximizeButtonState = YoYoStudio.Controls.CustomWindow.WindowButtonState.Disabled; //MinimizeButtonState = YoYoStudio.Controls.CustomWindow.WindowButtonState.Disabled; if (vm != null) { playMusicVM = vm; playMusicVM.Initialize(); } DataContext = playMusicVM; InitializeComponent(); musicControl.MoviePath = vm.MusicFlexPath; musicControl.FlashCallback += musicControl_FlashCallback; Closing += PlayMusicWindow_Closing; ShowInTaskbar = true; }
void RoomCallback_ReportMusicStatusEvent(int arg1, int arg2) { Dispatcher.BeginInvoke((Action)(() => { PlayMusicWindowViewModel vm = DataContext as PlayMusicWindowViewModel; string[] result = flex.CallFlash(FlexCommand.GetPlayStatus); if (result != null) { var playStatus = flex.CallFlash(FlexCommand.GetPlayStatus).ToList(); if (playStatus.Count == 2) { MusicStatus status = new MusicStatus(); status.PlayerId = vm.RoomWindowVM.Me.Id; status.Name = playStatus[0]; status.Status = (PlayStatus)Enum.Parse(typeof(PlayStatus), playStatus[1]); //status.Position = (int)(Decimal.Parse(playStatus[2]))+1; vm.RoomWindowVM.RoomClient.UpadateMusicStatus(vm.RoomWindowVM.RoomVM.Id, vm.RoomWindowVM.Me.Id, status, arg2); } } })); }
private void flex_FlashCallback(YoYoStudio.Controls.Winform.FlexCallbackCommand cmd, List <string> args) { PlayMusicWindowViewModel vm = DataContext as PlayMusicWindowViewModel; switch (cmd) { case FlexCallbackCommand.None: break; case FlexCallbackCommand.ReportStatus: if (args != null && args.Count == 1) { if (args[0] == FlexStatusStrings.ConnectSucceed) { //the connection has been setup with Red5 if (vm != null) { vm.RoomWindowVM.RoomCallback.StartMusicEvent += RoomCallback_StartMusicEvent; vm.RoomWindowVM.RoomCallback.TogglePauseMusicEvent += RoomCallback_TogglePauseMusicEvent; vm.RoomWindowVM.RoomCallback.SetMusicVolumeEvent += RoomCallback_SetMusicVolumeEvent; vm.RoomWindowVM.RoomCallback.SetPlayPositionEvent += RoomCallback_SetPlayPositionEvent; vm.RoomWindowVM.RoomCallback.StopMusicEvent += RoomCallback_StopMusicEvent; vm.RoomWindowVM.RoomCallback.ReportMusicStatusEvent += RoomCallback_ReportMusicStatusEvent; vm.RoomWindowVM.RoomCallback.UpdateMusicStatusEvent += RoomCallback_UpdateMusicStatusEvent; } } } break; case FlexCallbackCommand.LoadComplete: //flex control has been loaded. Next we will connect the Rmtp and load the musics if (vm != null) { CallFlash(FlexCommand.ConnectRTMP, vm.MusicRtmpUrl); CallFlash(FlexCommand.LoadMusics); SynchronizePlayStatus(); } break; case FlexCallbackCommand.PlayMusic: vm.RoomWindowVM.RoomClient.StartMusic(vm.RoomWindowVM.RoomVM.Id, vm.Me.Id, args[0]); break; case FlexCallbackCommand.StopMusic: vm.RoomWindowVM.RoomClient.StopMusic(vm.RoomWindowVM.RoomVM.Id, vm.Me.Id); break; case FlexCallbackCommand.SetPlayPosition: //vm.RoomWindowVM.RoomClient.SetPlayPosition(vm.RoomWindowVM.RoomVM.Id, vm.Me.Id, int.Parse(args[0])); break; case FlexCallbackCommand.SetVolume: //vm.RoomWindowVM.RoomClient.SetMusicVolume(vm.RoomWindowVM.RoomVM.Id, vm.Me.Id, int.Parse(args[0])); break; case FlexCallbackCommand.TogglePauseMusic: //if (args != null && args.Count == 1) //{ // if (args[0] == FlexStatusStrings.MusicPaused) // { // vm.RoomWindowVM.RoomClient.TogglePauseMusic(vm.RoomWindowVM.RoomVM.Id, vm.Me.Id, true); // } // else // { // vm.RoomWindowVM.RoomClient.TogglePauseMusic(vm.RoomWindowVM.RoomVM.Id, vm.Me.Id,false); // } //} break; default: break; } if (FlashCallback != null) { FlashCallback(cmd, args); } }