private void StartMusicOnHoldPlayback(object sender, AudioVideoFlowConfigurationRequestedEventArgs args) { _mohServer._mohPlayer.AttachFlow(args.Flow); _mohServer._mohPlayer.StateChanged += this.OnPlayerStateChanged; _mohServer._mohFileSource.BeginPrepareSource( MediaSourceOpenMode.Buffered, ar => { WmaFileSource fileSource = ar.AsyncState as WmaFileSource; try { fileSource.EndPrepareSource(ar); _mohServer._mohPlayer.Start(); } catch (OperationFailureException ex) { _mohServer.BeginShutDown( sar => { AcdMusicOnHoldServer mohServer = sar.AsyncState as AcdMusicOnHoldServer; mohServer.EndShutDown(sar); }, _mohServer); this.SetAsCompleted(ex, false); } }, _mohServer._mohFileSource); }
internal void Process() { _mohServer._mohFileSource.BeginPrepareSource( MediaSourceOpenMode.Buffered, ar => { WmaFileSource fileSource = ar.AsyncState as WmaFileSource; try { fileSource.EndPrepareSource(ar); _mohServer._mohPlayer.Start(); lock (_mohServer._syncRoot) { _mohServer.UpdateState(MusicOnHoldServerState.Started); } this.SetAsCompleted(null, false); } catch (OperationFailureException ex) { _mohServer.BeginShutDown( sar => { AcdMusicOnHoldServer mohServer = sar.AsyncState as AcdMusicOnHoldServer; mohServer.EndShutDown(sar); }, _mohServer); this.SetAsCompleted(ex, false); } }, _mohServer._mohFileSource); }
private void source_PrepareSourceCompleted(IAsyncResult result) { WmaFileSource source = (WmaFileSource)result.AsyncState; source.EndPrepareSource(result); _waitForPrepareSourceCompleted.Set(); }
private void CreatePlayer() { var source = new WmaFileSource("music.wma"); source.EndPrepareSource(source.BeginPrepareSource(MediaSourceOpenMode.Buffered, null, null)); _player = new Player(); _player.SetSource(source); _player.SetMode(PlayerMode.Manual); _player.StateChanged += player_StateChanged; _player.Start(); }
private void CreatePlayer() { var source = new WmaFileSource("music.wma"); source.EndPrepareSource(source.BeginPrepareSource(MediaSourceOpenMode.Buffered, null, null)); _player = new Player(); _player.SetSource(source); _player.SetMode(PlayerMode.Manual); _player.StateChanged += player_StateChanged; _player.Start(); }
void Flow_StateChanged(object sender, MediaFlowStateChangedEventArgs e) { Log("Flow_StateChanged PreviousState=" + e.PreviousState + " State=" + e.State); AudioVideoFlow avFlow = (AudioVideoFlow)sender; if (avFlow.State == MediaFlowState.Active) { Player player = new Player(); player.StateChanged += new EventHandler <PlayerStateChangedEventArgs>(player_StateChanged); player.AttachFlow(avFlow); WmaFileSource src = new WmaFileSource(_FileName); src.BeginPrepareSource(MediaSourceOpenMode.Buffered, ar => { try { src.EndPrepareSource(ar); player.SetSource(src); // For some reason, PlayerMode.Automatic does not loop audio player.SetMode(PlayerMode.Manual); player.Start(); Log("Playing \"" + _FileName + "\""); } catch (Exception ex) { Log(ex.ToString()); } }, null); } else if (avFlow.State == MediaFlowState.Terminated) { if (avFlow.Player != null) { if (avFlow.Player.Source != null) { avFlow.Player.Source.Close(); } avFlow.Player.DetachFlow(avFlow); } } }
protected override void StartupCore() { try { m_mohFileSource = new WmaFileSource(m_mohFilePath); m_mohPlayer = new Player(); m_mohPlayer.SetMode(PlayerMode.Manual); m_mohPlayer.SetSource(m_mohFileSource); m_mohPlayer.StateChanged += this.OnPlayerStateChanged; m_mohFileSource.BeginPrepareSource( MediaSourceOpenMode.Buffered, ar => { try { m_mohFileSource.EndPrepareSource(ar); m_mohPlayer.Start(); this.CompleteStartup(null); } catch (InvalidOperationException ioe) { this.CompleteStartup(ioe); } catch (OperationFailureException rte) { this.CompleteStartup(rte); } }, null); } catch (InvalidOperationException ioe) { this.CompleteStartup(ioe); } }
void Flow_StateChanged(object sender, MediaFlowStateChangedEventArgs e) { Log("Flow_StateChanged PreviousState=" + e.PreviousState + " State=" + e.State); AudioVideoFlow avFlow = (AudioVideoFlow)sender; if (avFlow.State == MediaFlowState.Active) { Player player = new Player(); player.StateChanged += new EventHandler<PlayerStateChangedEventArgs>(player_StateChanged); player.AttachFlow(avFlow); WmaFileSource src = new WmaFileSource(_FileName); src.BeginPrepareSource(MediaSourceOpenMode.Buffered, ar=> { try { src.EndPrepareSource(ar); player.SetSource(src); // For some reason, PlayerMode.Automatic does not loop audio player.SetMode(PlayerMode.Manual); player.Start(); Log("Playing \"" + _FileName + "\""); } catch (Exception ex) { Log(ex.ToString()); } }, null); } else if (avFlow.State == MediaFlowState.Terminated) { if (avFlow.Player != null) { if (avFlow.Player.Source != null) { avFlow.Player.Source.Close(); } avFlow.Player.DetachFlow(avFlow); } } }