예제 #1
0
        public override IBassStream CreateInteractiveStream(PlaylistItem playlistItem, IEnumerable <IBassStreamAdvice> advice, BassFlags flags)
        {
            var drive    = default(int);
            var id       = default(string);
            var track    = default(int);
            var fileName = this.GetFileName(playlistItem, advice);

            if (!CdUtils.ParseUrl(fileName, out drive, out id, out track))
            {
                //This shouldn't happen as CanCreateStream would have returned false.
                return(BassStream.Empty);
            }
            this.AssertDiscId(drive, id);
            var channelHandle = default(int);

            lock (SyncRoot)
            {
                if (this.GetCurrentStream(drive, track, out channelHandle))
                {
                    return(this.CreateInteractiveStream(channelHandle, advice, flags));
                }
                if (this.Output != null && this.Output.PlayFromMemory)
                {
                    Logger.Write(this, LogLevel.Warn, "This provider cannot play from memory.");
                }
                if (BassCd.FreeOld)
                {
                    Logger.Write(this, LogLevel.Debug, "Updating config: BASS_CONFIG_CD_FREEOLD = FALSE");
                    BassCd.FreeOld = false;
                }
                channelHandle = BassCd.CreateStream(drive, track, flags);
            }
            return(this.CreateInteractiveStream(channelHandle, advice, flags));
        }
예제 #2
0
        public override bool CanCreateStream(PlaylistItem playlistItem)
        {
            //The behaviour is not loaded for utilities so we can't check whether it's enabled.
            //if (this.Behaviour == null || !this.Behaviour.Enabled)
            //{
            //    return false;
            //}
            var drive = default(int);
            var id    = default(string);
            var track = default(int);

            return(CdUtils.ParseUrl(playlistItem.FileName, out drive, out id, out track));
        }
예제 #3
0
        protected virtual bool GetDrive(out int drive)
        {
            var outputStream = this.PlaybackManager.CurrentStream;

            if (outputStream == null)
            {
                drive = default(int);
                return(false);
            }
            var id    = default(string);
            var track = default(int);

            return(CdUtils.ParseUrl(outputStream.FileName, out drive, out id, out track));
        }
예제 #4
0
        public Task InvokeAsync(IInvocationComponent component)
        {
            switch (component.Id)
            {
            case OPEN_CD:
                var drive = CdUtils.GetDrive(component.Name);
                if (drive == CdUtils.NO_DRIVE)
                {
                    break;
                }
                return(this.OpenCd(drive));
            }
#if NET40
            return(TaskEx.FromResult(false));
#else
            return(Task.CompletedTask);
#endif
        }
예제 #5
0
        public async Task <PlaylistItem[]> Create()
        {
            var info = default(CDInfo);

            BassUtils.OK(BassCd.GetInfo(this.Drive, out info));
            var id            = BassCd.GetID(this.Drive, CDID.CDPlayer);
            var directoryName = string.Format("{0}:\\", info.DriveLetter);
            var playlistItems = new List <PlaylistItem>();

            for (int a = 0, b = BassCd.GetTracks(this.Drive); a < b; a++)
            {
                if (BassCd.GetTrackLength(this.Drive, a) == -1)
                {
                    //Not a music track.
                    continue;
                }
                var fileName = CdUtils.CreateUrl(this.Drive, id, a);
                var metaData = default(MetaDataItem[]);
                try
                {
                    metaData = (
                        await this.MetaDataSource.GetMetaData(fileName).ConfigureAwait(false)
                        ).ToArray();
                }
                catch (Exception e)
                {
                    metaData = new MetaDataItem[] { };
                    Logger.Write(this, LogLevel.Debug, "Failed to read meta data from file \"{0}\": {1}", fileName, e.Message);
                }
                Logger.Write(this, LogLevel.Debug, "Adding file to playlist: {0}", fileName);
                var playlistItem = new PlaylistItem()
                {
                    DirectoryName = directoryName,
                    FileName      = Path.Combine(fileName, this.GetFileName(fileName, a, metaData)),
                    Status        = PlaylistItemStatus.Import
                };
                playlistItem.MetaDatas = metaData;
                playlistItems.Add(playlistItem);
            }
            return(playlistItems.ToArray());
        }
예제 #6
0
        public Task <IEnumerable <MetaDataItem> > GetMetaData(string fileName)
        {
            var drive = default(int);
            var id    = default(string);
            var track = default(int);

            if (!CdUtils.ParseUrl(fileName, out drive, out id, out track))
            {
                //TODO: Warn.
#if NET40
                return(TaskEx.FromResult(Enumerable.Empty <MetaDataItem>()));
#else
                return(Task.FromResult(Enumerable.Empty <MetaDataItem>()));
#endif
            }
            var metaData = new List <MetaDataItem>();
            metaData.AddRange(this.Strategy.GetMetaDatas(track));
            metaData.AddRange(this.Strategy.GetProperties(track));
#if NET40
            return(TaskEx.FromResult <IEnumerable <MetaDataItem> >(metaData));
#else
            return(Task.FromResult <IEnumerable <MetaDataItem> >(metaData));
#endif
        }