/// <summary>
        /// Creates an <see cref="IInputSource"/> object for a given mediaitem.
        /// </summary>
        /// <param name="resourceLocator">Locator instance to the media item to create the input source for.</param>
        /// <param name="mimeType">Mime type of the media item, if present. May be <c>null</c>.</param>
        /// <returns>Input source object for the given <paramref name="resourceLocator"/> or <c>null</c>, if no input source
        /// could be created.</returns>
        public IInputSource CreateInputSource(IResourceLocator resourceLocator, string mimeType)
        {
            if (!CanPlay(resourceLocator, mimeType))
            {
                return(null);
            }
            IInputSource result;

            _accessor = resourceLocator.CreateAccessor();

            AudioCDResourceAccessor acdra = _accessor as AudioCDResourceAccessor;

            if (acdra != null)
            {
                result = BassCDTrackInputSource.Create(acdra.Drive, acdra.TrackNo);
            }
            else
            {
                string filePath = _accessor.ResourcePathName;
                // Network streams
                INetworkResourceAccessor netra = _accessor as INetworkResourceAccessor;
                if (netra != null)
                {
                    result = BassWebStreamInputSource.Create(netra.URL);
                }
                // CDDA
                else if (URLUtils.IsCDDA(filePath))
                {
                    ILocalFsResourceAccessor lfra = _accessor as ILocalFsResourceAccessor;
                    if (lfra == null)
                    {
                        return(null);
                    }
                    using (lfra.EnsureLocalFileSystemAccess())
                        result = BassFsCDTrackInputSource.Create(lfra.LocalFileSystemPath);
                }
                else
                {
                    // Filesystem resources
                    IFileSystemResourceAccessor fsra = _accessor as IFileSystemResourceAccessor;
                    if (fsra == null)
                    {
                        return(null);
                    }
                    if (URLUtils.IsMODFile(filePath))
                    {
                        result = BassMODFileInputSource.Create(fsra);
                    }
                    else
                    {
                        result = BassAudioFileInputSource.Create(fsra);
                    }
                }
            }
            Log.Debug("InputSourceFactory: Creating input source for media resource '{0}' of type '{1}'", _accessor, result.GetType());
            return(result);
        }
Example #2
0
        /// <summary>
        /// Creates an <see cref="IInputSource"/> object for a given mediaitem.
        /// </summary>
        /// <param name="resourceLocator">Locator instance to the media item to create the input source for.</param>
        /// <param name="mimeType">Mime type of the media item, if present. May be <c>null</c>.</param>
        /// <returns>Input source object for the given <paramref name="resourceLocator"/> or <c>null</c>, if no input source
        /// could be created.</returns>
        public IInputSource CreateInputSource(IResourceLocator resourceLocator, string mimeType)
        {
            if (!CanPlay(resourceLocator, mimeType))
            {
                return(null);
            }
            IInputSource result;

            using (IResourceAccessor accessor = resourceLocator.CreateAccessor())
            {
                AudioCDResourceAccessor acdra = accessor as AudioCDResourceAccessor;
                if (acdra != null)
                {
                    result = BassCDTrackInputSource.Create(acdra.Drive, acdra.TrackNo);
                }
                else
                {
                    string filePath = accessor.ResourcePathName;
                    if (URLUtils.IsCDDA(filePath))
                    {
                        ILocalFsResourceAccessor lfra = accessor as ILocalFsResourceAccessor;
                        if (lfra == null)
                        {
                            return(null);
                        }
                        result = BassFsCDTrackInputSource.Create(lfra.LocalFileSystemPath);
                    }
                    else
                    {
                        IFileSystemResourceAccessor fsra = accessor as ILocalFsResourceAccessor;
                        if (fsra == null)
                        {
                            return(null);
                        }
                        if (URLUtils.IsMODFile(filePath))
                        {
                            result = BassMODFileInputSource.Create(fsra);
                        }
                        else
                        {
                            result = BassAudioFileInputSource.Create(fsra);
                        }
                    }
                    // TODO: Handle web streams when we have resource accessors for web URLs: BassWebStreamInputSource.Create(...);
                }
                Log.Debug("InputSourceFactory: Creating input source for media resource '{0}' of type '{1}'", accessor, result.GetType());
            }

            return(result);
        }