예제 #1
0
            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);
            }
예제 #2
0
            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);
            }
예제 #3
0
        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();
 }
예제 #5
0
        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();
        }
예제 #6
0
        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);
                }
            }
        }
예제 #7
0
        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);
            }
        }
예제 #8
0
        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);
                }
            }
        }