コード例 #1
0
        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");
            }
        }
コード例 #2
0
        /// <summary>
        /// starts the playback of the given song
        /// </summary>
        /// <param name="playlistItem"></param>
        public void Play(PlaylistItem playlistItem)
        {
            if (_mediaPlayerFactory == null ||
                _mediaPlayerFactory.PlayerControllerType != _mediaPlayerFactory.GetPlayerControllerTypeForPlaylistItem(playlistItem))
            {
                if (_mediaPlayerFactory != null)
                {
                    _mediaPlayerFactory.PlayerController.Close();
                }

                var playerWindow = _container.Resolve <VideoPlayerWindowView>();
                _mediaPlayerFactory = new MediaPlayerFactory(playlistItem, playerWindow);
            }

            _mediaPlayerFactory.PlayerController.Play(playlistItem);
        }