public PlayerVlcService() { var currentAssembly = Assembly.GetEntryAssembly(); try { if (currentAssembly != null) { var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName; if (currentDirectory == null) { return; } var vlcLibDirectory = new DirectoryInfo(Path.Combine(currentDirectory, @"lib\x86")); _vlcMediaPlayer = new VlcMediaPlayer(vlcLibDirectory); } else { throw new FileNotFoundException(Localization.strings.PlayerEngineNotFound); } } catch (Exception e) { LoggerFacade.WriteError(Localization.strings.PlayerNotLoaded, e, isShow: true); } _vlcMediaPlayer.EndReached += VlcMediaPlayer_OnEndReached; _vlcMediaPlayer.PositionChanged += VlcMediaPlayer_OnPositionChanged; _vlcMediaPlayer.LengthChanged += VlcMediaPlayer_OnLengthChanged; _vlcMediaPlayer.Stopped += VlcMediaPlayer_OnStopped; _vlcMediaPlayer.Paused += VlcMediaPlayer_OnPaused; _vlcMediaPlayer.Playing += VlcMediaPlayer_OnPlaying; }
public void SetPosition(float position) { try { _vlcMediaPlayer.Position = position; } catch (Exception e) { LoggerFacade.WriteError(e); } }
public void Stop() { try { _vlcMediaPlayer.Pause(); } catch (Exception e) { LoggerFacade.WriteError(e); } }
public void Play(Uri playPathUri) { try { _vlcMediaPlayer.Play(playPathUri.AbsoluteUri); } catch (Exception e) { LoggerFacade.WriteError(e); } }
public static void Handle(Exception ex, bool forceShutdown = false, bool isSilent = false) { // TODO: localize LoggerFacade.WriteError(GetLogMessage(ex)); var shutdown = forceShutdown; // возможна ситуация когда происходит подряд сразу несколько критических исключений, // в этом случае отображаем только первое и завершаем работу, остальные только логируем. if (shutdown && !IsShuttingDown.TrySet()) { return; } if (!isSilent || shutdown) { var sourceEx = ExtractException(ex); var message = sourceEx.Message + "Unknown error occurred."; if (shutdown) { message += Environment.NewLine + "Application will be closed. Please contact developers for support." + Environment.NewLine + "Restart Application ?"; } // при вызове из App_OnDispatcherUnhandledException, стандартный MessageBox работает надёжно. UiInvoker.Invoke(() => { MessageBoxResult result; if (Application.Current.MainWindow != null) { result = MessageBox.Show(Application.Current.MainWindow, message, AppInfo.AppName, MessageBoxButton.YesNo, MessageBoxImage.Error); } else { // произошло ещё до инициализации главного окна result = MessageBox.Show(message, AppInfo.AppName, MessageBoxButton.YesNo, MessageBoxImage.Error); } if (result == MessageBoxResult.Yes) { System.Windows.Forms.Application.Restart(); } }); } if (shutdown) { Environment.Exit(0); } }
public static async Task <BitmapImage> GetBitmapFromUrl(string url) { return(await Task.Run(() => { try { var image = new BitmapImage(); int BytesToRead = 100; if (url.Contains("?ava=1")) { url = url.Replace("?ava=1", ""); } WebRequest request = WebRequest.Create(new Uri(url)); request.Timeout = -1; WebResponse response = request.GetResponse(); Stream responseStream = response.GetResponseStream(); BinaryReader reader = new BinaryReader(responseStream); MemoryStream memoryStream = new MemoryStream(); byte[] bytebuffer = new byte[BytesToRead]; int bytesRead = reader.Read(bytebuffer, 0, BytesToRead); while (bytesRead > 0) { memoryStream.Write(bytebuffer, 0, bytesRead); bytesRead = reader.Read(bytebuffer, 0, BytesToRead); } image.BeginInit(); memoryStream.Seek(0, SeekOrigin.Begin); image.StreamSource = memoryStream; image.EndInit(); image.Freeze(); return image; } catch (Exception e) { LoggerFacade.WriteError("load photo error", e); return null; } })); }
public void Pause(bool doPause) { try { if (doPause) { _vlcMediaPlayer.Pause(); } else { _vlcMediaPlayer.Play(); } } catch (Exception e) { LoggerFacade.WriteError(e); } }