/// <summary> /// Open/Choose File dialog invoked from: /// - Menu Open File /// - Open file button /// </summary> public void OpenFile() { Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog(); //ofd.Filter = "Video MP4|*.mp4|Video M4V|*.m4v|All|*.*"; ofd.Filter = MediaDecoder.ExtensionsFilter(); bool?result = ofd.ShowDialog(); if (result.GetValueOrDefault(false)) { OpenURI(ofd.FileName); } }
public void FileDropped(DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { // Note that you can have more than one file. string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); string ext = Path.GetExtension(files[0]); //if (Path.GetExtension(files[0]) == ".mp4") if (MediaDecoder.CheckExtension(Path.GetExtension(files[0]))) { OpenURI(files[0]); } else { NotificationCenter.PushNotification(new NotificationViewModel("File format not supported.")); } } ShowDropFilesPanel(false); if (IsFileSelected == false) { ShowStartupPanel(true); } PlaybackControlUIHitTestVisible(true); }
private void EnableRemoteControl() { Task.Factory.StartNew((System.Action)(() => { remoteControl = ApiServer.InitNancy(apiServer => { remoteLogger.Info("got unity init, device_id=" + ApiServer.device_id + " movies=[\n" + string.Join(",\n", ApiServer.movies) + "]"); remoteLogger.Info("init complete"); } ); #region GearVR slave app ApiServer.OnBackPressed += () => { remoteLogger.Info("back pressed"); }; ApiServer.OnStateChange += (state) => { remoteLogger.Info("state changed: " + state); switch (state) { //case ApiServer.State.off: // Execute.OnUIThreadAsync(() => // { // if(IsPlaying) // Stop(); // }); // break; case ApiServer.State.pause: Execute.OnUIThreadAsync(() => { if (IsPlaying && !IsPaused) { Pause(); _mediaDecoder.Seek(remoteTime); } }); break; case ApiServer.State.play: Execute.OnUIThreadAsync((System.Action)(() => { if (!_ready) { this.OpenURI((string)SelectedFileName); } else { PlayPause(); } })); break; case ApiServer.State.stop: Execute.OnUIThreadAsync(() => { if (IsPlaying) { Stop(); } }); break; } }; ApiServer.OnConfirmPlay += (path) => { remoteLogger.Info("path = " + path); string remoteFile = path.Split('/').Last(); if (File.Exists(Logic.Instance.settings.RemoteControlMovieDirectory + Path.DirectorySeparatorChar + remoteFile)) { IsFileSelected = true; SelectedFileName = Logic.Instance.settings.RemoteControlMovieDirectory + Path.DirectorySeparatorChar + remoteFile; } else { IsFileSelected = false; SelectedFileName = ""; Execute.OnUIThreadAsync(() => NotificationCenter.PushNotification(new NotificationViewModel("Requested file \"" + remoteFile + "\" not found in video library.", () => { System.Diagnostics.Process.Start(Logic.Instance.settings.RemoteControlMovieDirectory); }, "open folder"))); } }; ApiServer.OnPos += (euler, t) => { //Log("[remote] position = " + euler.Item1 + ", " + euler.Item2 + ", " + euler.Item3, ConsoleColor.DarkGreen); //remoteTime = (float)(t * MaxTime); //if (DXCanvas.Scene != null) //{ // ((Scene)DXCanvas.Scene).SetLook(euler); //} }; ApiServer.OnPosQuaternion += (quat, t) => { //Log("[remote] position = " + quat.Item1 + ", " + euler.Item2 + ", " + euler.Item3, ConsoleColor.DarkGreen); remoteTime = (float)(t * MaxTime); if (DXCanvas.Scene != null) { ((Scene)DXCanvas.Scene).SetLook(quat); } }; ApiServer.OnInfo += (msg) => { remoteLogger.Info("[remote] msg = " + msg); }; #endregion #region Remote controll app - control API ApiServer.CommandLoadHandler = (movie, autoplay) => { remoteLogger.Info("[remote] path = " + movie); string remoteFile = movie.Contains('/') ? movie.Split('/').Last() : movie; if (File.Exists(Logic.Instance.settings.RemoteControlMovieDirectory + Path.DirectorySeparatorChar + remoteFile)) { IsFileSelected = true; SelectedFileName = Logic.Instance.settings.RemoteControlMovieDirectory + Path.DirectorySeparatorChar + remoteFile; this.LoadMedia(autoplay); return(true); } else { IsFileSelected = false; SelectedFileName = ""; Execute.OnUIThreadAsync(() => NotificationCenter.PushNotification(new NotificationViewModel("Requested file \"" + remoteFile + "\" not found in video library.", () => { System.Diagnostics.Process.Start(Logic.Instance.settings.RemoteControlMovieDirectory); }, "open folder"))); return(false); } }; ApiServer.CommandMoviesHandler = () => { List <string> movies = new List <string>(); var dir = Logic.Instance.settings.RemoteControlMovieDirectory; if (Directory.Exists(dir)) { try { var files = Directory.GetFiles(dir); foreach (string file in files) { if (MediaDecoder.CheckExtension(Path.GetExtension(file))) { movies.Add(Path.GetFileName(file)); } } } catch (Exception exc) { } } return(movies.ToArray()); }; ApiServer.CommandPauseHandler = () => { if (IsPlaying && !IsPaused) { Pause(); return(true); } return(false); }; ApiServer.CommandPlayingHandler = () => { var info = new ApiServer.PlayingInfo() { is_playing = false, movie = "", quat_x = 0f, quat_y = 0f, quat_z = 0f, quat_w = 0f, t = 0, tmax = 0 }; if (IsFileSelected) { info.movie = SelectedFileName; } if (IsPlaying) { info.is_playing = !IsPaused; if (this.DXCanvas.Scene != null) { var q = ((Scene)this.DXCanvas.Scene).GetCurrentLook(); info.quat_x = q.X; info.quat_y = q.Y; info.quat_z = q.Z; info.quat_w = q.W; } info.t = (float)TimeValue; info.tmax = (float)MaxTime; } return(info); }; ApiServer.CommandSeekHandler = (time) => { if (IsPlaying) { TimeValue = time; return(true); } return(false); }; ApiServer.CommandStopAndResetHandler = () => { if (IsPlaying) { Stop(); return(true); } return(false); }; ApiServer.CommandUnpauseHandler = () => { if (IsPlaying && IsPaused) { UnPause(); return(true); } if (!IsPlaying && IsFileSelected) { PlayPause(); return(true); } return(false); }; #endregion IsRemoteControlEnabled = true; })); }
public ShellViewModel() { InitHeadsets(); ShellViewModel.Instance = this; ShellViewModel.OnInstantiated?.Invoke(this); var currentParser = Parser.CreateTrigger; Parser.CreateTrigger = (target, triggerText) => ShortcutParser.CanParse(triggerText) ? ShortcutParser.CreateTrigger(triggerText) : currentParser(target, triggerText); NotifyOfPropertyChange(() => PlayerTitle); CurrentPosition = "00:00:00"; VideoLength = "00:00:00"; NotificationCenter = new NotificationCenterViewModel(); _mediaDecoder = new MediaDecoder(); _mediaDecoder.Loop = Loop; _mediaDecoder.OnReady += (duration) => { _ready = true; SendEvent("movieLoaded", Path.GetFileName(SelectedFileName)); if (autoplay) { autoplay = false; urlLoadLock = false; Play(); } }; _mediaDecoder.OnEnded += () => { SendEvent("movieEnded", Path.GetFileName(SelectedFileName)); Task.Factory.StartNew(() => Execute.OnUIThread(() => { Stop(); ShowStartupUI(); })); }; _mediaDecoder.OnStop += () => { Task.Factory.StartNew(() => waitForPlaybackStop.Set()); SendEvent("movieStopped", Path.GetFileName(SelectedFileName)); }; _mediaDecoder.OnTimeUpdate += (time) => { if (!_mediaDecoder.IsPlaying) { return; } Execute.OnUIThreadAsync(() => { if (!lockSlider) { VRUIUpdatePlaybackTime(time); CurrentPosition = (new TimeSpan(0, 0, (int)Math.Floor(time))).ToString(); _timeValue = time; NotifyOfPropertyChange(() => TimeValue); } UpdateTimeLabel(); }); }; _mediaDecoder.OnError += (error) => { urlLoadLock = false; Execute.OnUIThreadAsync(() => { NotificationCenter.PushNotification(MediaDecoderHelper.GetNotification(error)); SelectedServiceResult = null; ShowStartupUI(); }); SendEvent("playbackError", error); }; _mediaDecoder.OnBufferingStarted += () => { Execute.OnUIThreadAsync(() => { shellView.BufferingStatus.Visibility = Visibility.Visible; }); }; _mediaDecoder.OnBufferingEnded += () => { Execute.OnUIThreadAsync(() => { shellView.BufferingStatus.Visibility = Visibility.Collapsed; }); }; _mediaDecoder.OnProgress += (progress) => { Execute.OnUIThreadAsync(() => { shellView.BufferingStatus.Text = $"Buffering... {progress}"; }); }; UpdateTimeLabel(); VolumeRocker = new VolumeControlViewModel(); VolumeRocker.Volume = 0.5; VolumeRocker.OnVolumeChange += (volume) => { _mediaDecoder.SetVolume(volume); ShellViewModel.SendEvent("volumeChanged", volume); }; Logic.Instance.OnUpdateAvailable += () => Execute.OnUIThreadAsync(() => { NotificationCenter.PushNotification( new NotificationViewModel( "A new version of Bivrost® 360Player is available.", () => { Updater.OnUpdateFail += () => Execute.OnUIThreadAsync(() => NotificationCenter.PushNotification(new NotificationViewModel("Something went wrong :("))); Updater.OnUpdateSuccess += () => Execute.OnUIThreadAsync(() => NotificationCenter.PushNotification(new NotificationViewModel("Update completed successfully.", () => { System.Windows.Forms.Application.Restart(); System.Windows.Application.Current.Shutdown(); }, "restart", 60f))); Execute.OnUIThreadAsync(() => NotificationCenter.PushNotification(new NotificationViewModel("Installing update..."))); Task.Factory.StartNew(() => Updater.InstallUpdate()); }, "install now" ) ); }); Logic.Instance.ValidateSettings(); }