Exemplo n.º 1
0
        /// <summary>
        /// Reads tags from a File.
        /// </summary>
        public static TagReader Read(string FileName)
        {
            Bass.Init();

            var h = Bass.CreateStream(FileName, Flags: BassFlags.Prescan);

            TagReader result = null;

            if (h != 0)
            {
                result = Read(h);

                Bass.StreamFree(h);
            }
            else
            {
                h = Bass.MusicLoad(FileName, Flags: BassFlags.Prescan);

                if (h != 0)
                {
                    result = Read(h);

                    Bass.MusicFree(h);
                }
            }

            if (!string.IsNullOrWhiteSpace(result?.Title))
            {
                result.Title = System.IO.Path.GetFileNameWithoutExtension(FileName);
            }

            return(result);
        }
Exemplo n.º 2
0
        static MediaPlayer()
        {
            var currentDev = Bass.CurrentDevice;

            if (currentDev == -1 || !Bass.GetDeviceInfo(Bass.CurrentDevice).IsInitialized)
            {
                Bass.Init(currentDev);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new instance of <see cref="Record"/>.
        /// </summary>
        public Record(RecordDevice Device, int Frequency, int Channels, Resolution Resolution = Resolution.Short)
        {
            Bass.Init(0);
            Device.Init();

            Bass.CurrentRecordingDevice = Device.Index;

            _handle = Bass.RecordStart(Frequency, Channels, BassFlags.RecordPause | Resolution.ToBassFlag(), Processing);

            AudioFormat = WaveFormat.FromChannel(_handle);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Loads a file into the player.
        /// </summary>
        /// <param name="FileName">Path to the file to Load.</param>
        /// <returns><see langword="true"/> on succes, <see langword="false"/> on failure.</returns>
        public async Task <bool> LoadAsync(string FileName)
        {
            try
            {
                if (Handle != 0)
                {
                    Bass.StreamFree(Handle);
                }
            }
            catch { }

            if (_dev != -1)
            {
                Bass.CurrentDevice = _dev;
            }

            var currentDev = Bass.CurrentDevice;

            if (currentDev == -1 || !Bass.GetDeviceInfo(Bass.CurrentDevice).IsInitialized)
            {
                Bass.Init(currentDev);
            }

            var h = await Task.Run(() => OnLoad(FileName));

            if (h == 0)
            {
                return(false);
            }

            Handle = h;

            var tags = TagReader.Read(Handle);

            Title = !string.IsNullOrWhiteSpace(tags.Title) ? tags.Title
                                                           : Path.GetFileNameWithoutExtension(FileName);
            Artist = tags.Artist;
            Album  = tags.Album;

            InitProperties();

            MediaLoaded?.Invoke(h);

            OnPropertyChanged("");

            return(true);
        }
Exemplo n.º 5
0
        private void OnLoad(object sender, EventArgs e)
        {
            _handle      = 0;
            _SpectrumIdx = 2; // Options.MainSettings.PlayerSpectrumIndex;

            labelInfo.Text = "00:00:00.000 / 00:00:00.000";

            _PositionTrack.Maximum = 100;
            _PositionTrack.Enabled = true;

            _CheckLoop.Checked = Loop;
            _VolumeTrack.Value = (int)(Volume * 100);

            // create a secure timer
            _UpdateTimer       = new BASSTimer(_UpdateInterval);
            _UpdateTimer.Tick += new EventHandler(timerUpdate_Tick);

            /*if (Bass.CurrentDevice == -1)
             * {
             *  // Using the play function for the first time
             *  Console.WriteLine("Player: Bass Initialisation");
             *
             *  Bass.Free();
             *
             *  if (!Bass.Init(_defaultSoundDevice, 44100, DeviceInitFlags.Default, IntPtr.Zero))
             *  {
             *      Console.WriteLine("Player: Error Init Bass: {0:G}", Bass.LastError);
             *      return;
             *  }
             * }*/

            // Bass.UpdatePeriod = 230;

            // Bass.Start(); return false

            if (!Bass.Configure(Configuration.IncludeDefaultDevice, true))
            {
                Console.WriteLine("Player: Error Configure Bass: {0:G}", Bass.LastError);
                return;
            }

            if (!Bass.Init())
            {
                Console.WriteLine("Player: Error Init Bass: {0:G}", Bass.LastError);
                return;
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Initialize a Device for Playback
 /// </summary>
 public bool Init(int Frequency = 44100, DeviceInitFlags Flags = DeviceInitFlags.Default)
 {
     return(Bass.Init(Index, Frequency, Flags));
 }