/// <inheritdoc /> public void Load(string fileName) { _networkstream = ExtensionProvider.IsNetworkStream(fileName); Log.Info("Loading file: {0}", fileName); if (_decodeChannel != 0 || _mixerChannel != 0) { Stop(); } try { Bass.StreamFree(_decodeChannel); } catch (Exception ex) { Debug.WriteLine(ex); } if (string.IsNullOrEmpty(fileName)) { Log.Error("Filename was null or empty. Aborted load"); return; } var sourceflags = BassFlags.Decode | BassFlags.Loop | BassFlags.Float | BassFlags.Prescan; var mixerflags = BassFlags.MixerDownMix | BassFlags.MixerPositionEx | BassFlags.AutoFree; if (_networkstream) { int r; lock (Lock) { // make sure only 1 thread at a time can do the following // increment the request counter for this request r = ++_req; } var netFlags = BassFlags.StreamDownloadBlocks | sourceflags; Bass.NetProxy = ""; //os default proxy _decodeChannel = Bass.CreateStream(fileName, 0, netFlags, _streamDloadProc, new IntPtr(r)); lock (Lock) { if (r != _req) { if (_decodeChannel != 0) { Bass.StreamFree(_decodeChannel); } return; } } _netadress = fileName; } else { if (ExtensionProvider.IsCdStream(fileName)) { var cd = new CDTrackInfo(fileName); _decodeChannel = BassCd.CreateStream(cd.Drive, cd.Track, sourceflags); Log.Info("Geting track metadata..."); UpdateCDTags(cd.Drive, cd.Track); } else { _decodeChannel = Bass.CreateStream(fileName, 0, 0, sourceflags); Log.Info("Geting track metadata..."); UpdateFileTags(fileName); } } if (_decodeChannel == 0) { Log.Error("Decode chanel creation failed: {0}", Bass.LastError); return; } var channelInfo = Bass.ChannelGetInfo(_decodeChannel); _mixerChannel = BassMix.CreateMixerStream(channelInfo.Frequency, channelInfo.Channels, mixerflags); if (_mixerChannel == 0) { Log.Error("Mixer chanel creation failed: {0}", Bass.LastError); return; } if (!BassMix.MixerAddChannel(_mixerChannel, _decodeChannel, BassFlags.MixerDownMix)) { Log.Error("Failed to route decoded stream to mixer: {0}", Bass.LastError); return; } if (!_networkstream) { Log.Info("Getting track length..."); var len = Bass.ChannelGetLength(_decodeChannel, PositionFlags.Bytes); _length = Bass.ChannelBytes2Seconds(_decodeChannel, len); NotifyChanged(nameof(Length)); Log.Info("Getting Chapters..."); Chapters.Clear(); Chapters.AddRange(ChapterFactory.GetChapters(fileName, _length)); } Volume = _LastVolume; Bass.ChannelSetAttribute(_mixerChannel, ChannelAttribute.Volume, Volume); Log.Info("Loaded file {0}", fileName); }