Exemplo n.º 1
0
        static MediaPlayer()
        {
            var currentDev = Bass.CurrentDevice;

            if (currentDev == -1 || !Bass.GetDeviceInfo(Bass.CurrentDevice).IsInitialized)
            {
                Bass.Init(currentDev);
            }
        }
Exemplo n.º 2
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.º 3
0
        /// <summary>
        /// Get Device by Index.
        /// </summary>
        public static PlaybackDevice GetByIndex(int Device)
        {
            if (Singleton.ContainsKey(Device))
            {
                return(Singleton[Device]);
            }

            DeviceInfo info;

            if (!Bass.GetDeviceInfo(Device, out info))
            {
                throw new ArgumentOutOfRangeException(nameof(Device), "Invalid PlaybackDevice Index");
            }

            var dev = new PlaybackDevice(Device);

            Singleton.Add(Device, dev);

            return(dev);
        }