Example #1
0
        /// <summary>
        /// Plays the given file to the specified channel.
        /// </summary>
        /// <param name="eventSocket">The EventSocket instance.</param>
        /// <param name="uuid">The Channel UUID.</param>
        /// <param name="file">The Path to the file to be played. Note: use forward slashes for path separators.</param>
        /// <param name="options">Options to customize playback.</param>
        /// <returns>A PlayResult.</returns>
        /// <exception cref="FileNotFoundException">Throws FileNotFoundException if FreeSwitch is unable to play the file.</exception>//todo: should it?
        public static async Task <PlayResult> Play(this EventSocket eventSocket, string uuid, string file, PlayOptions options = null)
        {
            // todo: implement options for playback eg a-leg, b-leg, both, using uuid_displace
            if (options == null)
            {
                options = new PlayOptions();
            }

            try
            {
                // todo: what if applicationresult is null (hang up occurs before the application completes)
                var result =
                    new PlayResult(
                        await
                        eventSocket.ExecuteApplication(uuid, "playback", file, loops: options.Loops)
                        .ConfigureAwait(false));

                if (!result.Success)
                {
                    LogFailedApplicationResult(eventSocket, result);
                }

                return(result);
            }
            catch (TaskCanceledException ex)
            {
                return(new PlayResult(null));
            }
        }
 void Start()
 {
     character            = GetComponent <Rigidbody>();
     characterCollider    = GetComponent <Collider>();
     characterNormalScale = transform.localScale;
     playMode             = PlayOptions.Explore;
 }
Example #3
0
 public Options()
 {
     Mirror = new MirrorOptions();
     Play   = new PlayOptions();
     Test   = new TestOptions();
     Server = new ServerOptions();
 }
        public async Task Play(PlayOptions options)
        {
            CurrentPlaylistIndex = 0;
            CurrentPlayOptions   = options;

            _playlist = options.Items.ToList();

            _currentPlaybackDispatcher = _presentation.Window.Dispatcher;

            try
            {
                _currentPlaybackDispatcher.Invoke(() =>
                {
                    _hiddenWindow.WindowsFormsHost.Child = _mediaPlayer = new DirectShowPlayer(_logger, _hiddenWindow, this)
                    {
                        BackColor   = Color.Black,
                        BorderStyle = BorderStyle.None
                    };

                    //HideCursor();
                });

                await PlayTrack(0, options.StartPositionTicks);
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error beginning playback", ex);

                DisposePlayer();

                throw;
            }
        }
Example #5
0
        /// <summary>
        /// Plays the specified player.
        /// </summary>
        /// <param name="player">The player.</param>
        /// <param name="options">The options.</param>
        /// <param name="configuration">The configuration.</param>
        /// <returns>Task.</returns>
        private async Task Play(IMediaPlayer player, PlayOptions options, PlayerConfiguration configuration)
        {
            if (options.Items[0].IsPlaceHolder ?? false)
            {
                // play a phyical disc in the cdrom drive
                // Will be re-entrant call, so has to be made befpre the interlocked.CompareExchange below
                await PlayExternalDisc(true);

                return;
            }

            if (Interlocked.CompareExchange(ref _isStarting, 1, 0) == 0) // prevent race conditions, thread safe check we are not already starting to play an item
            {
                try
                {
                    if (options.Shuffle)
                    {
                        options.Items = options.Items.OrderBy(i => Guid.NewGuid()).ToList();
                    }

                    var firstItem = options.Items[0];


                    if (options.StartPositionTicks == 0 && player.SupportsMultiFilePlayback && firstItem.IsVideo && firstItem.LocationType == LocationType.FileSystem && options.GoFullScreen)
                    {
                        try
                        {
                            var intros = await _apiClient.GetIntrosAsync(firstItem.Id, _apiClient.CurrentUserId);

                            options.Items.InsertRange(0, intros.Items);
                        }
                        catch (Exception ex)
                        {
                            _logger.ErrorException("Error retrieving intros", ex);
                        }
                    }


                    options.Configuration = configuration;

                    await player.Play(options);

                    if (player is IInternalMediaPlayer && player is IVideoPlayer && firstItem.IsVideo)
                    {
                        await _presentationManager.Window.Dispatcher.InvokeAsync(() => _presentationManager.WindowOverlay.SetResourceReference(FrameworkElement.StyleProperty, "WindowBackgroundContentDuringPlayback"));

                        if (options.GoFullScreen)
                        {
                            await _nav.NavigateToInternalPlayerPage();
                        }
                    }
                    OnPlaybackStarted(player, options);
                }
                finally
                {
                    Interlocked.Exchange(ref _isStarting, 0);
                }
            }
        }
 /// <summary>
 /// Gets the process start info.
 /// </summary>
 /// <param name="items">The items.</param>
 /// <param name="options">The options.</param>
 /// <param name="playerConfiguration">The player configuration.</param>
 /// <returns>ProcessStartInfo.</returns>
 protected virtual ProcessStartInfo GetProcessStartInfo(List<BaseItemDto> items, PlayOptions options, PlayerConfiguration playerConfiguration)
 {
     return new ProcessStartInfo
     {
         FileName = playerConfiguration.Command,
         Arguments = GetCommandArguments(items, options, playerConfiguration)
     };
 }
Example #7
0
        static int RunPlay(PlayOptions options)
        {
            var engine = new DesktopEngine();

            engine.Server.Run(engine);

            return(0);
        }
Example #8
0
        /// <summary>
        /// Starts playing sound
        /// </summary>
        /// <param name="soundEffect"></param>
        /// <param name="options"></param>
        /// <param name="volume"></param>
        /// <param name="pitch"></param>
        public void PlaySound(SoundEffect soundEffect, PlayOptions options = PlayOptions.None)
        {
            soundInstance = soundEffect.CreateInstance();

            soundInstance.IsLooped = options.HasFlag(PlayOptions.Looped);

            soundInstance.Play();
        }
Example #9
0
		/// <summary>
		/// Starts playing sound
		/// </summary>
		/// <param name="soundEffect"></param>
		/// <param name="options"></param>
		/// <param name="volume"></param>
		/// <param name="pitch"></param>
		public void PlaySound ( SoundEffect soundEffect, PlayOptions options = PlayOptions.None )
		{
			soundInstance	=	soundEffect.CreateInstance();

			soundInstance.IsLooped	=	options.HasFlag(PlayOptions.Looped);

			soundInstance.Play(); 
		}
Example #10
0
        /// <summary>
        /// Play media full screen
        /// Some movies (DIVX) take a long time to load so this is required
        /// </summary>
        public void PlayMediaFullScreen(PlayOptions playOption)
        {
            UserPressedStop = false;
            LoadingNextFile = true;

            _mediaPreviewModel.CancelPreviews();
            PlayOptions = playOption;

            Thread playthread = new Thread(new ThreadStart(delegate
            {
                bool crashing = true;
                while (crashing)
                {
                    try
                    {
                        this.MediaPlayer.URL             = PageModel.GetInstance.SelectedMenuItemModel.FilePath;
                        this.MediaPlayer.settings.volume = 100;

                        this.MediaPlayer.Ctlcontrols.currentPosition = 0;
                        this.MediaPlayer.Ctlcontrols.play();
                        crashing = false;
                    }
                    catch
                    {
                        Thread.Sleep(20);
                    }
                }

                SetToFullScreen();

                // Playing full screen, give focus back to form1.
                Application.Current.Dispatcher.Invoke(() =>
                {
                    Application.Current.MainWindow.Focus();
                });


                // Fix bug where pressing play too quick goes back to non-full screen.

                // Sleep for a bit.
                Thread.Sleep(1000);

                SetToFullScreen();

                // Playing full screen, give focus back to form1.
                Application.Current.Dispatcher.Invoke(() => {
                    Application.Current.MainWindow.Focus();
                });

                LoadingNextFile = false;

                Task.Run(() => { KeepFullScreen(); });
            }));

            playthread.Name         = "playThread";
            playthread.IsBackground = true;
            playthread.Start();
        }
Example #11
0
        private void PlayInternal(PlayOptions options)
        {
            EnsureMediaPlayerCreated();

            CurrentPlaylistIndex = 0;
            CurrentPlayOptions   = options;

            _playlist = options.Items.ToList();
            _isPaused = false;

            var path = options.Items.First().Path;

            try
            {
                //var media = new PathMedia(@"D:\\Video\\TV\\30 Rock\\Season 1\\30 Rock - 1x02 - The Aftermath.mkv");
                var media = path.StartsWith("http", StringComparison.OrdinalIgnoreCase) ?
                            (MediaBase) new LocationMedia(path) :
                            (MediaBase) new PathMedia(path);

                //media.StateChanged +=
                //    delegate(MediaBase s, VlcEventArgs<States> args)
                //    {
                //        if (args.Data == States.Ended)
                //        {
                //            var subItems = media.SubItems;
                //            if (subItems.Count > 0)
                //            {
                //                _vlcControl.Play(subItems[0]);
                //            }
                //        }
                //    };
                //media.MediaSubItemAdded +=
                //    delegate(MediaBase s, VlcEventArgs<MediaBase> args)
                //    {
                //        _vlcControl.Media = args.Data;
                //        _vlcControl.Play();
                //    };

                _vlcControl = new VlcControl();

                _vlcControl.Media        = media;
                _vlcControl.PlaybackMode = PlaybackModes.Loop;
                _vlcControl.Stopped     += _vlcControl_Stopped;
                _vlcControl.Paused      += _vlcControl_Paused;
                _vlcControl.Playing     += _vlcControl_Playing;
                _vlcControl.Play();

                _vlcControl.SetHandle(_hiddenWindow.Form.Handle);

                _userInput.GlobalKeyDown += _userInput_KeyDown;
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error beginning playback", ex);

                DisposePlayer();
            }
        }
        /// <summary>
        /// Plays the internal.
        /// </summary>
        /// <param name="items">The items.</param>
        /// <param name="options">The options.</param>
        /// <param name="playerConfiguration">The player configuration.</param>
        protected override void PlayInternal(List<BaseItemDto> items, PlayOptions options, PlayerConfiguration playerConfiguration)
        {
            App.Instance.ApplicationWindow.Dispatcher.Invoke(() =>
            {
                App.Instance.ApplicationWindow.BackdropContainer.Visibility = Visibility.Collapsed;
                App.Instance.ApplicationWindow.WindowBackgroundContent.SetResourceReference(FrameworkElement.StyleProperty, "WindowBackgroundContentDuringPlayback");
            });

            App.Instance.NavigateToInternalPlayerPage();
        }
Example #13
0
        /// <summary>
        /// Called when [playback started].
        /// </summary>
        /// <param name="player">The player.</param>
        /// <param name="options">The options.</param>
        private async void OnPlaybackStarted(IMediaPlayer player, PlayOptions options)
        {
            EventHelper.QueueEventIfNotNull(PlaybackStarted, this, new PlaybackStartEventArgs
            {
                Options = options,
                Player  = player
            }, _logger);

            await new PlaybackProgressReporter(_apiClient, player, _logger, this).Start().ConfigureAwait(false);
        }
Example #14
0
    public void Play(MovieCallback callback)
    {
        this.options          = new PlayOptions();
        this.options.callback = callback;
        string methodName = string.Empty;

        methodName = "PlayPC";
        if (methodName != string.Empty)
        {
            base.StartCoroutine(methodName, this.options);
        }
    }
        /// <summary>
        /// Enables the madvr.
        /// </summary>
        /// <param name="options">The options.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        private bool EnableReclock(PlayOptions options)
        {
            var video = options.Items.First();

            if (!video.IsVideo)
            {
                return(false);
            }

            if (!_config.Configuration.InternalPlayerConfiguration.EnableReclock)
            {
                return(false);
            }

            return(true);
        }
Example #16
0
 public void PlaySound(AudioClip audioClip, PlayOptions options = null, Action onStopCallback = null)
 {
     gameObject.SetActive(true);
     _audioSource.clip = audioClip;
     // instantiate the delay counter
     if (null != options)
     {
         _loopCount  = options.loopCount;
         _delayTimer = new Timer(options.startDelay);
     }
     else
     {
         PlaySound();
     }
     // set the callback on stop, if any
     _onStopCallback = onStopCallback;
 }
Example #17
0
        /// <summary>
        /// Plays the specified options.
        /// </summary>
        /// <param name="options">The options.</param>
        /// <returns>Task.</returns>
        public async Task Play(PlayOptions options)
        {
            _currentIsoMount = options.Items.Count == 1 && options.Configuration.IsoMethod == IsoConfiguration.Mount ?
                               await GetIsoMount(options.Items[0], CancellationToken.None) :
                               null;

            CurrentPlaylistIndex = 0;
            CurrentPlayOptions   = options;

            _playlist = options.Items.ToList();

            var process = new Process
            {
                EnableRaisingEvents = true,
                StartInfo           = GetProcessStartInfo(options.Items, options, _currentIsoMount)
            };

            Logger.Info("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);

            try
            {
                process.Start();
            }
            catch (Exception ex)
            {
                Logger.ErrorException("Error starting player", ex);

                _playlist.Clear();

                throw;
            }

            if (options.Configuration.CloseOnStopButton && !CanCloseAutomaticallyOnStopButton)
            {
                _userInput.GlobalKeyDown += KeyboardListener_KeyDown;
            }

            process.Exited += CurrentProcess_Exited;

            _currentProcess = process;

            OnPlayerLaunched();
        }
Example #18
0
        /// <summary>
        /// Plays the specified options.
        /// </summary>
        /// <param name="options">The options.</param>
        /// <returns>Task.</returns>
        public Task Play(PlayOptions options)
        {
            return(Task.Run(() =>
            {
                CurrentPlaylistIndex = 0;
                CurrentPlayOptions = options;

                _playlist = options.Items.ToList();

                var process = new Process
                {
                    EnableRaisingEvents = true,
                    StartInfo = GetProcessStartInfo(options.Items, options)
                };

                Logger.Info("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);

                try
                {
                    process.Start();
                }
                catch (Exception ex)
                {
                    Logger.ErrorException("Error starting player", ex);

                    _playlist.Clear();

                    throw;
                }

                if (options.Configuration.CloseOnStopButton && !CanCloseAutomaticallyOnStopButton)
                {
                    _userInput.KeyDown += KeyboardListener_KeyDown;
                }

                process.Exited += CurrentProcess_Exited;

                _currentProcess = process;

                OnPlayerLaunched();
            }));
        }
Example #19
0
        public async Task Play(PlayOptions options)
        {
            CurrentPlaylistIndex = 0;
            CurrentPlayOptions   = options;

            _playlist = options.Items.ToList();

            try
            {
                await PlayTrack(0, options.StartPositionTicks);
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error beginning playback", ex);

                DisposePlayer();

                throw;
            }
        }
Example #20
0
 public void PlayClip(
     AudioClip clip,
     float volume            = 1,
     PlayOptions playOptions = PlayOptions.PlayOnce)
 {
     AudioSource.clip         = clip;
     AudioSource.volume       = volume;
     AudioSource.time         = 0;
     AudioSource.spatialBlend = 1;
     AudioSource.Play();
     if (playOptions == PlayOptions.Loop)
     {
         AudioSource.loop = true;
         StartCoroutine(SlowUpdate());
     }
     else
     {
         StartCoroutine(DestroyWithDelay(clip.length));
     }
 }
Example #21
0
        /// <summary>
        /// Called when [playback started].
        /// </summary>
        /// <param name="player">The player.</param>
        /// <param name="options">The options.</param>
        private async void OnPlaybackStarted(IMediaPlayer player, PlayOptions options)
        {
            EventHelper.QueueEventIfNotNull(PlaybackStarted, this, new PlaybackStartEventArgs
            {
                Options = options,
                Player  = player
            }, _logger);

            lock (_reporterLock)
            {
                if (_reporter != null)
                {
                    _reporter.Dispose();
                    _reporter = null;
                }
            }

            _reporter = new PlaybackProgressReporter(_apiClient, player, _logger, this);
            await _reporter.Start().ConfigureAwait(false);
        }
    private void ChoosePlayMode()
    {
        PlayOptions currentPlayMode = playMode;

        Debug.Log("Current play mode = " + currentPlayMode);
        if (Input.GetButtonDown("TogglePlayModeRight"))
        {
            switch (currentPlayMode)
            {
            case PlayOptions.Explore:
                playMode = PlayOptions.Combat;
                break;

            case PlayOptions.Sneak:
                playMode = PlayOptions.Explore;
                break;

            case PlayOptions.Combat:
                playMode = PlayOptions.Sneak;
                break;
            }
        }

        if (Input.GetButtonDown("TogglePlayModeLeft"))
        {
            switch (currentPlayMode)
            {
            case PlayOptions.Explore:
                playMode = PlayOptions.Sneak;
                break;

            case PlayOptions.Sneak:
                playMode = PlayOptions.Combat;
                break;

            case PlayOptions.Combat:
                playMode = PlayOptions.Explore;
                break;
            }
        }
    }
Example #23
0
        /// <summary>
        /// Enables the madvr.
        /// </summary>
        /// <param name="options">The options.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        private bool EnableMadvr(PlayOptions options)
        {
            var video = options.Items.First();

            if (!video.IsVideo)
            {
                return(false);
            }

            if (!_config.Configuration.InternalPlayerConfiguration.VideoConfig.EnableMadvr)
            {
                return(false);
            }

            if (!options.GoFullScreen)
            {
                return(false);
            }

            return(true);
        }
Example #24
0
        public AudioHandle Play(string clipId, PlayOptions options)
        {
            AudioClip clip = GetClip(clipId);

            if (clip != null)
            {
                AudioHandle     handle     = GetSource();
                AudioSourceInfo sourceInfo = GetSourceInfo(handle);
                if (sourceInfo != null)
                {
                    AudioSource source = sourceInfo.Source;
                    source.clip = clip;
                    source.loop = options.Loop;
                    source.transform.localPosition = options.Position;

                    sourceInfo.ClipId       = clipId;
                    sourceInfo.TargetVolume = options.Volume;

                    if (options.FadeInTime > 0.0f &&
                        !_isMuted)
                    {
                        sourceInfo.VolumeFluctuationSpeed = sourceInfo.TargetVolume / options.FadeInTime;
                        source.volume = 0.0f;
                    }
                    else
                    {
                        SetSourceVolume(sourceInfo, sourceInfo.TargetVolume);
                    }

                    source.Play();

                    handle._handle_audio_source = source;
                }

                return(handle);
            }

            return(new AudioHandle());
        }
Example #25
0
        /// <summary>
        /// Plays the specified player.
        /// </summary>
        /// <param name="player">The player.</param>
        /// <param name="options">The options.</param>
        /// <param name="configuration">The configuration.</param>
        /// <returns>Task.</returns>
        private async Task Play(IMediaPlayer player, PlayOptions options, PlayerConfiguration configuration)
        {
            if (options.Shuffle)
            {
                options.Items = options.Items.OrderBy(i => Guid.NewGuid()).ToList();
            }

            var firstItem = options.Items[0];

            if (options.StartPositionTicks == 0 && player.SupportsMultiFilePlayback && firstItem.IsVideo && firstItem.LocationType == LocationType.FileSystem && options.GoFullScreen)
            {
                try
                {
                    var intros = await _apiClient.GetIntrosAsync(firstItem.Id, _apiClient.CurrentUserId);

                    options.Items.InsertRange(0, intros.Items);
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error retrieving intros", ex);
                }
            }

            options.Configuration = configuration;

            await player.Play(options);

            if (player is IInternalMediaPlayer && player is IVideoPlayer && firstItem.IsVideo)
            {
                await _presentationManager.Window.Dispatcher.InvokeAsync(() => _presentationManager.WindowOverlay.SetResourceReference(FrameworkElement.StyleProperty, "WindowBackgroundContentDuringPlayback"));

                if (options.GoFullScreen)
                {
                    await _nav.NavigateToInternalPlayerPage();
                }
            }

            OnPlaybackStarted(player, options);
        }
Example #26
0
        /// <summary>
        /// Plays the specified options.
        /// </summary>
        /// <param name="options">The options.</param>
        /// <returns>Task.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// options
        /// or
        /// options
        /// </exception>
        /// <exception cref="System.InvalidOperationException">There are no available players.</exception>
        public async Task Play(PlayOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            if (options.Items == null || options.Items.Count(i => i.LocationType != LocationType.Offline) == 0)
            {
                throw new ArgumentException("At least one item must be supplied.");
            }

            PlayerConfiguration config;
            var player = GetPlayer(options.Items, out config);

            if (player == null)
            {
                throw new InvalidOperationException("There are no available players.");
            }

            StopAllPlayback();

            await Play(player, options, config);
        }
Example #27
0
        private void PlayAllEx(PlayOptions options)
        {
            if (SelectedSyl == -1) return;

            if (PlayStatus == ReproductionState.Play)
            {
                mW.audio.Stop();
                PlayStatus = ReproductionState.Stop;
                return;
            }

            int ms_iniciales = 0, ms_finales = 0;
            for (int i = 0; i < SelectedSyl; i++)
            {
                K tmp = (K)OurK[i];
                ms_iniciales += tmp.Milliseconds;
            }
            K sel = (K)OurK[SelectedSyl];
            ms_finales = ms_iniciales + sel.Milliseconds;

            double begin_off = (double)ms_iniciales / 100;
            double end_off = (double)ms_finales / 100;

            Mode = PlayMode.Other;
            PlayStatus = ReproductionState.Play;

            double begin = Tiempo.TimeToSecondDouble(infoTiempoInicial.Text) + begin_off;
            double off = Tiempo.TimeToSecondDouble(infoTiempoInicial.Text) + end_off; //Tiempo.TimeToSecondDouble(infoTiempoFinal.Text);

            switch (options)
            {
                case PlayOptions.BeforeStart:
                    off = begin;
                    begin = Math.Max(0, off - .5);
                    break;

                case PlayOptions.BeforeEnd:
                    begin = Math.Max(0, off - .5);
                    break;

                case PlayOptions.AfterStart:
                    off = begin + .5;
                    break;

                case PlayOptions.AfterEnd:
                    begin = off;
                    off = begin + .5;
                    break;
            }
            PosRel = begin - Tiempo.TimeToSecondDouble(infoTiempoInicial.Text);
            LastEnd = off-Tiempo.TimeToSecondDouble(infoTiempoInicial.Text);
            unsafe
            {
                byte* buf = (byte*)AudioFull.ToPointer();
                byte* buf_final = buf;

                int principio = (int)(begin * avsaudio.AudioSampleRate * avsaudio.BytesPerSample);
                if (principio % 2 == 1) principio++;
                buf += principio;

                buf_final += (int)(off * avsaudio.AudioSampleRate * avsaudio.BytesPerSample);

                int size = (int)(buf_final - buf);
                if (size % 2 == 1) size++;

                if (size > 0)
                {

                    byte[] rangeplay = new byte[size];
                    IntPtr buff = new IntPtr(buf);

                    Marshal.Copy(buff, rangeplay, 0, size);

                    mW.audio = avs2ds.PreparaAudio(rangeplay);
                    AudioActualPosition_Refresh.Enabled = true;
                    mW.audio.Play(0, BufferPlayFlags.Default);

                }

            }
        }
        /// <summary>
        /// Plays the internal.
        /// </summary>
        /// <param name="items">The items.</param>
        /// <param name="options">The options.</param>
        /// <param name="playerConfiguration">The player configuration.</param>
        protected override void PlayInternal(List<BaseItemDto> items, PlayOptions options, PlayerConfiguration playerConfiguration)
        {
            EnsureMediaPlayerCreated();

            _currentPlaylistIndex = 0;

            MediaList = MediaPlayerFactory.CreateMediaList<IMediaList>(items.Select(GetPlayablePath));
            VideoPlayer = MediaPlayerFactory.CreateMediaListPlayer<IMediaListPlayer>(MediaList);

            VideoPlayer.InnerPlayer.WindowHandle = WindowsFormsPanel.Handle;

            VideoPlayer.InnerPlayer.Events.PlayerStopped += Events_PlayerStopped;
            VideoPlayer.Play();

            var position = options.StartPositionTicks;

            if (position > 0)
            {
                VideoPlayer.Time = Convert.ToInt64(TimeSpan.FromTicks(position).TotalMilliseconds);
            }

            VideoPlayer.MediaListPlayerEvents.MediaListPlayerNextItemSet += MediaListPlayerEvents_MediaListPlayerNextItemSet;

            base.PlayInternal(items, options, playerConfiguration);
        }
Example #29
0
 /// <summary>
 /// Plays the specified options.
 /// </summary>
 /// <param name="options">The options.</param>
 /// <returns>Task.</returns>
 public async Task Play(PlayOptions options)
 {
     InvokeOnPlayerThread(() => PlayInternal(options));
 }
Example #30
0
 private IEnumerator PlayPC(PlayOptions options)
 {
     return(new < PlayPC > c__Iterator273 {
         options = options, <$> options = options, <> f__this = this
     });
Example #31
0
        private void AudioPlayEx(PlayOptions options)
        {
            if (AudioState == ReproductionState.Play)
            {
                AudioActualPosition_Refresh_500.Enabled = false;
                AudioState = ReproductionState.Stop;
                audio.Stop();
                audio.Dispose();
                audio = null;
                return;
            }

            double inicio = Tiempo.TimeToSecondDouble(textInicio.Text);
            double fin = 0;

            if (AudioGrid_Inicio == -1) return;

            if (AudioGrid_Fin != -1)
                fin = Tiempo.TimeToSecondDouble(textFin.Text);
            else
                if (options == PlayOptions.BeforeEnd || options == PlayOptions.AfterEnd)
                    return;

            switch (options)
            {
                case PlayOptions.BeforeStart:

                    if (inicio < .5)
                    {
                        inicio = 0;
                        fin = .5;
                    }
                    else
                    {
                        inicio -= .5;
                        fin = inicio + .5;
                    }

                    break;
                case PlayOptions.AfterStart:
                    fin = inicio + .5;
                    break;

                case PlayOptions.BeforeEnd:
                    fin = Tiempo.TimeToSecondDouble(textFin.Text);
                    inicio = fin - .5;

                    if (inicio < 0) inicio = 0;
                    break;
                case PlayOptions.AfterEnd:
                    inicio = Tiempo.TimeToSecondDouble(textFin.Text);
                    fin = inicio + .5;

                    break;
                case PlayOptions.Normal:
                    inicio = Tiempo.TimeToSecondDouble(textInicio.Text);
                    fin = Tiempo.TimeToSecondDouble(textFin.Text);
                    break;
            }

            audioGrid_Inicio_500 = inicio;
            audioGrid_Fin_500 = fin;

            InicioPlay = inicio;

            unsafe
            {

                byte* buf = (byte*)AudioFull.ToPointer();
                byte* buf_final = buf;
                buf += (int)(inicio * avsaudio.AudioSampleRate * avsaudio.BytesPerSample);

                IntPtr tmp = new IntPtr(buf);
                int tesuto = tmp.ToInt32();

                if ((tesuto % 2) == 1) buf++;

                //if (tesuto >= mainW.idx0rz) return;

                int max_or_mult = (int)Math.Min((int)(fin * avsaudio.AudioSampleRate * avsaudio.BytesPerSample), mainW.idx0rz);
                buf_final += max_or_mult;

                int size = (int)(buf_final - buf);

                if (size < 0) return;

                AudioTemp = new byte[size];
                IntPtr buff = new IntPtr(buf);

                Marshal.Copy(buff, AudioTemp, 0, size);
                audio = avs2ds.PreparaAudio(AudioTemp);
                audio.Play(0, BufferPlayFlags.Default);
                AudioState = ReproductionState.Play;
                AudioActualPosition_Refresh_500.Enabled = true;
            }
        }
Example #32
0
        /// <summary>
        /// Handles Windows media player key strokes
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="T:System.Windows.Input.KeyEventArgs" /> instance containing the event data.</param>
        public void HandleKeyDown(object sender, KeyEventArgs e)
        {
            if (BlockKeyPresses)
            {
                //e.IsInputKey = false;
                return;
            }
            BlockKeyPresses = true;

            // stop
            if (e.Key == Key.MediaStop || e.Key == Key.V)
            {
                if (!LoadingNextFile)
                {
                    UserPressedStop = true;
                    PlayOptions     = PlayOptions.Play;
                    //IsFullScreen = false;
                    //IsPlaying = false;
                    MediaPlayer.Ctlcontrols.stop();
                    MediaPlayer.fullScreen = false;
                    Application.Current.MainWindow.Focus();
                    PreviewMedia(false);
                }
            }

            // Skip forwards
            if (e.Key == Key.MediaNextTrack || e.Key == Key.N)
            {
                SkipForward(40);
            }

            // skip backwards
            if (e.Key == Key.P || e.Key == (Key)177 || e.Key == Key.MediaPreviousTrack)
            {
                SkipBackwards(40);
            }

            // Skip forwards (long)
            if (e.Key == Key.Right)
            {
                SkipForward(700);
            }

            // skip backwards (long)
            if (e.Key == Key.Left)
            {
                SkipBackwards(700);
            }

            // play, pause. note: this is required both here and in playPanel
            if (e.Key == Key.MediaPlayPause || e.Key == (Key)179 || e.Key == Key.Play)
            {
                if (MediaPlayer.playState == WMPLib.WMPPlayState.wmppsPaused)
                {
                    MediaPlayer.Ctlcontrols.play();
                }
                else
                {
                    MediaPlayer.Ctlcontrols.pause();
                }
            }

            BlockKeyPresses = false;
        }
        /// <summary>
        /// Plays the internal.
        /// </summary>
        /// <param name="items">The items.</param>
        /// <param name="options">The options.</param>
        /// <param name="playerConfiguration">The player configuration.</param>
        protected override void PlayInternal(List<BaseItemDto> items, PlayOptions options, PlayerConfiguration playerConfiguration)
        {
            CurrentProcess = new Process
            {
                EnableRaisingEvents = true,
                StartInfo = GetProcessStartInfo(items, options, playerConfiguration)
            };

            Logger.Info("{0} {1}", CurrentProcess.StartInfo.FileName, CurrentProcess.StartInfo.Arguments);

            CurrentProcess.Start();

            OnExternalPlayerLaunched();

            if (!CanCloseAutomatically)
            {
                KeyboardListener.KeyDown += KeyboardListener_KeyDown;
            }

            CurrentProcess.Exited += CurrentProcess_Exited;
        }
        /// <summary>
        /// Gets the command arguments.
        /// </summary>
        /// <param name="items">The items.</param>
        /// <param name="options">The options.</param>
        /// <param name="playerConfiguration">The player configuration.</param>
        /// <returns>System.String.</returns>
        protected virtual string GetCommandArguments(List<BaseItemDto> items, PlayOptions options, PlayerConfiguration playerConfiguration)
        {
            var args = playerConfiguration.Args;

            if (string.IsNullOrEmpty(args))
            {
                return string.Empty;
            }

            return GetCommandArguments(items, args);
        }
 internal static extern int playAudio(int sourceIndex, PlayOptions playOptions);
Example #36
0
 /// <summary>
 /// Gets the process start info.
 /// </summary>
 /// <param name="items">The items.</param>
 /// <param name="options">The options.</param>
 /// <returns>ProcessStartInfo.</returns>
 protected virtual ProcessStartInfo GetProcessStartInfo(IEnumerable <BaseItemDto> items, PlayOptions options)
 {
     return(new ProcessStartInfo
     {
         FileName = options.Configuration.Command,
         Arguments = GetCommandArguments(items, options)
     });
 }
Example #37
0
 /// <summary>
 /// Gets the command arguments.
 /// </summary>
 /// <param name="items">The items.</param>
 /// <param name="options">The options.</param>
 /// <returns>System.String.</returns>
 protected virtual string GetCommandArguments(IEnumerable <BaseItemDto> items, PlayOptions options)
 {
     return(GetCommandArguments(items, options.Configuration.Args));
 }
Example #38
0
        public void Play(string path, PlayOptions po = PlayOptions.localPlayer, string PlayerPath = "", string WorkingDirectory = "")
        {
            P = new Process();
            bool flag = po == PlayOptions.localPlayer;

            if (flag)
            {
                try
                {
                    P.StartInfo.FileName = path;
                    bool flag2 = WorkingDirectory != "";
                    if (flag2)
                    {
                        P.StartInfo.WorkingDirectory = WorkingDirectory;
                    }
                    P.Start();
                }
                catch
                {
                    throw new Exception("文件无法读取或无打开方式");
                }
            }
            else
            {
                bool flag3 = po == PlayOptions.ffplay;
                if (flag3)
                {
                    bool flag4 = !File.Exists(ffplayPath);
                    if (flag4)
                    {
                        throw new FileNotFoundException("ffplay路径不存在或未设置");
                    }
                    P.StartInfo.FileName = ffplayPath;
                    string text  = "";
                    bool   flag5 = path.Substring(0, 1) != "\"";
                    if (flag5)
                    {
                        text = "\"" + path;
                    }
                    bool flag6 = path.Substring(path.Length - 1, 1) != "\"";
                    if (flag6)
                    {
                        text += "\"";
                    }
                    P.StartInfo.Arguments = "-i " + text;
                    bool flag7 = WorkingDirectory != "";
                    if (flag7)
                    {
                        P.StartInfo.WorkingDirectory = WorkingDirectory;
                    }
                    P.Start();
                }
                else
                {
                    bool flag8 = po == PlayOptions.Custom;
                    if (flag8)
                    {
                        bool flag9 = !File.Exists(PlayerPath);
                        if (flag9)
                        {
                            throw new FileNotFoundException("播放器路径无效");
                        }
                        P.StartInfo.FileName  = PlayerPath;
                        P.StartInfo.Arguments = (path ?? "");
                        bool flag10 = WorkingDirectory != "";
                        if (flag10)
                        {
                            P.StartInfo.WorkingDirectory = WorkingDirectory;
                        }
                        P.Start();
                    }
                }
            }
        }
Example #39
0
        public AudioHandle Play(string clipId, PlayOptions options)
        {
            AudioClip clip = GetClip (clipId);
            if (clip != null) {
                AudioHandle handle = GetSource ();
                AudioSourceInfo sourceInfo = GetSourceInfo (handle);
                if (sourceInfo != null) {
                    AudioSource source = sourceInfo.Source;
                    source.clip = clip;
                    source.loop = options.Loop;
                    source.transform.localPosition = options.Position;

                    sourceInfo.ClipId = clipId;
                    sourceInfo.TargetVolume = options.Volume;

                    if (options.FadeInTime > 0.0f &&
                        !_isMuted) {
                        sourceInfo.VolumeFluctuationSpeed = sourceInfo.TargetVolume / options.FadeInTime;
                        source.volume = 0.0f;
                    }
                    else {
                        SetSourceVolume (sourceInfo, sourceInfo.TargetVolume);
                    }

                    source.Play ();

                    handle._handle_audio_source = source;
                }

                return handle;
            }

            return new AudioHandle ();
        }