Exemple #1
0
        /// <summary>
        /// Plays a media file
        /// </summary>
        /// <param name="fileName"></param>
        public void Play(string fileName)
        {
            if (String.IsNullOrWhiteSpace(fileName))
            {
                throw new ArgumentNullException("Please specifiy a filename");
            }

            // Get the format
            var fileFormat = fileName.Substring(fileName.LastIndexOf('.') + 1).ToLower();

            // Check it
            if (String.IsNullOrWhiteSpace(fileFormat))
            {
                throw new ArgumentNullException("Please specifiy a valid file to play");
            }

            // This object can play 'wav' files, however, any other format requires another player
            switch (fileFormat)
            {
            case "wav":
                Console.WriteLine();
                break;

            default:
                _playerAdapter.Play(fileName);      // Use the adapter
                break;
            }
        }
Exemple #2
0
 void OnPlayButtonClickHandler()
 {
     if (rawImage.enabled)
     {
         if (vPlayer.isPlaying)
         {
             vPlayer.Pause();
             playButton.GetComponent <Image>().sprite = playImage;
         }
         else
         {
             vPlayer.Play();
             playButton.GetComponent <Image>().sprite = pauseImage;
         }
     }
 }
        /// <summary>
        /// plays the currently selected song, if no song is selected it plays the first one inside the playlist,
        /// if no song is inside the playlist, the random function is used to get a song from the library
        /// </summary>
        private void Play()
        {
            if (_mediaPlayer.IsPlaying())
            {
                if (PlaybackPaused)
                {
                    Pause();
                    return;
                }
                _mediaPlayer.Stop();
            }
            if (CurrentSong == null && PlaylistService != null)
            {
                CurrentSong = PlaylistService.GetNextPlaylistItem(SequentialPlayback == false, null, true);
            }
            if (CurrentSong == null)
            {
                return;
            }

            _mediaPlayer.Play(CurrentSong);
            PlaybackPaused = false;

            PreviousSongCommand.RaiseCanExecuteChanged();

            PauseCommand.RaiseCanExecuteChanged();
            ((IPlayerView)View).SetArtistAndTitle(CurrentSong.Song.Artist, CurrentSong.Song.Title);
            int durationOfSongInMs = _mediaPlayer.GetDurationOfPlayedSong();

            ((IPlayerView)View).SetSongDuration(durationOfSongInMs);
        }
Exemple #4
0
        private bool ExecuteEmptyResponse(IMediaPlayer mediaPlayer, BaseRequest message, Stream outStream)
        {
            switch (message)
            {
            case SetVolume m: mediaPlayer.SetVolume(m.Volume); break;

            case SetMute m: mediaPlayer.SetMute(m.IsMuted); break;

            case SetPlaybackSpeed m: mediaPlayer.SetPlaybackSpeed(m.Speed); break;

            case SetAudioTrack m: mediaPlayer.SetAudioTrack(m.TrackId); break;

            case SetVideoTrack m: mediaPlayer.SetVideoTrack(m.TrackId); break;

            case Play _: mediaPlayer.Play(); break;

            case Pause _: mediaPlayer.Pause(); break;

            case LocalFileStreamDisconnect _: mediaPlayer.DisconnectLocalFileStream(); break;

            case StepForward _: mediaPlayer.StepForward(); break;

            case StepBack _: mediaPlayer.StepBack(); break;

            case Seek m: mediaPlayer.Seek(m.Position); break;

            default: return(false);
            }

            responseService.ReturnEmptyResponse(outStream, message);

            return(true);
        }
Exemple #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);
                }
            }
        }
        public void Handle(string command)
        {
            switch (command)
            {
            case "/play":
                player.Play();
                break;

            case "/pause":
                player.Pause();
                break;

            case "/next":
                player.Play();
                break;
            }
        }
Exemple #7
0
        private void Play(Track source)
        {
            var fileToPlay = new Uri(source.Location);

            if (_mediaPlayer.Source == null || !_mediaPlayer.Source.Equals(fileToPlay))
            {
                _mediaPlayer.Open(fileToPlay);
                //Playing.Text = source.Name;
            }
            _mediaPlayer.Play();
        }
        public void Process(string[] args)
        {
            /* code that parses the arguments */

            if (args.Length < 2)
            {
                throw new Exception("Not enough parameters provided");
            }

            string operation = args[0];
            string file      = args[1];
            string extension = Path.GetExtension(file);

            extension = extension.Substring(1, extension.Length - 1);


            bool isSupportedFormat = Enum.TryParse(extension, ignoreCase: true, out MediaFormat format);

            IMediaPlugIn mediaPlugIn      = null;
            int          effectStartIndex = 2;

            if (!isSupportedFormat)
            {
                if (args.Length < 4)
                {
                    throw new Exception("Custom media type requires plugin asembly path and it's type");
                }
                format           = MediaFormat.Custom;
                mediaPlugIn      = GetMediaPlugIn(args[2], args[3]);
                effectStartIndex = 4;
            }
            string[] effects = args.Skip(effectStartIndex).ToArray(); //new string[args.Length - effectStartIndex+1];
            //args.CopyTo(effects, effectStartIndex);

            IMediaEffect[] mediaEffects = GetMediaEffects(effects);

            MediaPlayerFactory factory = new MediaPlayerFactory();
            IMediaPlayer       player  = factory.GetMediaPlayer(format, mediaPlugIn);

            Enum.TryParse(operation, out MediaOperation mediaOperation);
            switch (mediaOperation)
            {
            case MediaOperation.Play:
                player.Play(file, mediaEffects);
                break;

            case MediaOperation.Decompress:
                player.Decompress(file);
                break;

            default: throw new InvalidOperationException("Operation not supported");
            }
        }
Exemple #9
0
        public void Process(string id, string jukeCoreMediaPath)
        {
            _console.WriteLine($"Processing ID {id}");

            var medias = _mediaFactory.Create(id, jukeCoreMediaPath);

            _playlist.Set(medias);

            var firstMedia = _playlist.Next();

            _mediaPlayer.Play(firstMedia);
        }
        public static Task PlayPause(this IMediaPlayer mediaPlayer)
        {
            var status = mediaPlayer.State;

            if (status == MediaPlayerState.Paused || status == MediaPlayerState.Stopped)
            {
                return(mediaPlayer.Play());
            }
            else
            {
                return(mediaPlayer.Pause());
            }
        }
Exemple #11
0
 private void PlayRecordedVoice()
 {
     AllowRecording = false;
     AllowStopping  = true;
     AllowPlaying   = false;
     AllowDeleting  = false;
     mediaState     = MediaState.PLAY;
     mediaPlayer.Play(mediaFilePath, (s, e) =>
     {
         AllowStopping = false;
         AllowPlaying  = true;
         AllowDeleting = true;
     });
 }
Exemple #12
0
        private void OnPressed(object sender, EventArgs e)
        {
            try
            {
                _console.WriteLine("Next button was pressed!");
                var media = _playlist.Next();

                ThreadPool.QueueUserWorkItem(_ => _mediaPlayer.Play(media));
            }
            catch (Exception exception)
            {
                _console.WriteLine(exception.Message);
            }
        }
Exemple #13
0
        private void PlayRecordedAudio()
        {
            if (string.IsNullOrEmpty(voiceNotePath))
            {
                return;
            }

            AllowPlaying  = false;
            AllowStopping = true;
            mediaPlayer.Play(voiceNotePath, (s, e) =>
            {
                AllowStopping = false;
                AllowPlaying  = true;
            });
        }
 public static void TogglePlayPause(this IMediaPlayer player)
 {
     if (player == null)
     {
         throw new ArgumentNullException(nameof(player));
     }
     if (player.IsPlaying)
     {
         player.Pause();
     }
     else
     {
         player.Play();
     }
 }
Exemple #15
0
 public void Play(string audioType, string fileName)
 {
     if (audioType == "Mp3")
     {
         Console.WriteLine("playing mp3 file name:" + fileName);
     }
     else if (audioType == "Vlc" || audioType == "Mp4")
     {
         _mediaPlayer = new MediaAdapter(audioType);
         _mediaPlayer.Play(audioType, fileName);
     }
     else
     {
         Console.WriteLine("Invalid media" + audioType + "format not supported");
     }
 }
 public void Play(string type, string name)
 {
     if (string.Compare(type, "avi", true) == 0)
     {
         Console.WriteLine("Playing avi video named: {0}", name);
     }
     else if (string.Compare(type, "mp4", true) == 0 || string.Compare(type, "vlc", true) == 0)
     {
         player = new MediaAdapter(type);
         player.Play(type, name);
     }
     else
     {
         Console.WriteLine("Invalid media. {0} format not supported.", type);
     }
 }
Exemple #17
0
        public void Play(AudioType audioType, string fileName)
        {
            switch (audioType)
            {
            case AudioType.MP3:
                Console.WriteLine($"Playing mp3 file. Name:{fileName}");
                break;

            case AudioType.VLC:
            case AudioType.MP4:
                mediaAdapter = new MediaAdapter(audioType);
                mediaAdapter.Play(audioType, fileName);
                break;

            default:
                Console.WriteLine($"Invalid media.{audioType} format not supported");
                break;
            }
        }
Exemple #18
0
 public void TogglePlayState()
 {
     if (Data.State is EpisodeStatePendingDownload)
     {
         Data.Download();
     }
     else if (Data.State is EpisodeStateDownloaded)
     {
         if (Data.Played)
         {
             Data.Position = TimeSpan.FromSeconds(0);
             Data.Played   = false;
         }
         Task t = m_MediaPlayer.Play(Data);
     }
     else if (Data.State is EpisodeStatePlaying)
     {
         m_MediaPlayer.Pause(Data);
     }
 }
        /// <summary>
        /// Called when a button is fired in the view
        /// </summary>
        /// <param name="obj">The object.</param>
        private void OnVideoControl(string obj)
        {
            switch (obj)
            {
            case "pause":
                _mediaElement.Pause();
                break;

            case "play":
                _mediaElement.Play();
                break;

            case "stop":
                _mediaElement.Stop();
                break;

            default:
                break;
            }
        }
Exemple #20
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);
        }
Exemple #21
0
        public ActionResult Get(string fileName)
        {
            _mediaPlayer.Play(fileName);

            return(Ok());
        }
        /// <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);
        }
Exemple #23
0
 // Starts video playback.
 public void Play()
 {
     mediaPlayer.Play();
 }
Exemple #24
0
 public void PlayMedia(string fileName)
 {
     _mediaPlayer.Play(fileName);
 }
Exemple #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.Items[0].IsPlaceHolder ?? false)
            {
                // play a phyical disk in the cdrom drive
                // Will be re-entrant call, so has to be made befpre the interlocked.CompareExchange below
                await PlayExternalDisk(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;

                    var playTask = player.Play(options);

                    if (player is IInternalMediaPlayer && player is IVideoPlayer && firstItem.IsVideo)
                    {
                        if (options.GoFullScreen)
                        {
                            await _nav.Navigate(Go.To.FullScreenPlayback());
                        }
                    }

                    await playTask;
                    OnPlaybackStarted(player, options);
                }
                finally
                {
                    Interlocked.Exchange(ref _isStarting, 0);
                }
            }
        }
 public async void Play(string directory)
 {
     await _player.Play(new File(directory));
 }
Exemple #27
0
 private void BtnPlay_Click(object sender, RoutedEventArgs e)
 {
     _mediaPlayerWrapper.Play();
 }
Exemple #28
0
    public void Main()
    {
        IMediaPlayer player = GetMediaPlayer();

        player.Play();
    }
        /// <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);
                }
            }
        }
 public void Play()
 {
     _player.Play();
 }
Exemple #31
0
 private static void PlayVideo(string url)
 {
     _mediaPlayer.Play(url);
 }