public static async Task<FlacMediaSourceAdapter> CreateAsync(IStorageFile file)
        {
            var fileStream = await file.OpenAsync(FileAccessMode.Read);
            var adapter = new FlacMediaSourceAdapter();
            adapter.Initialize(fileStream);

            return adapter;
        }
Example #2
0
        public static async Task <FlacMediaSourceAdapter> CreateAsync(IStorageFile file)
        {
            var fileStream = await file.OpenAsync(FileAccessMode.Read);

            var adapter = new FlacMediaSourceAdapter();

            adapter.Initialize(fileStream);

            return(adapter);
        }
Example #3
0
        private async void InternalStartTrack(QueueSong track)
        {
            _transportControls.IsPreviousEnabled = !IsRadioMode;

            // If the flac media source adapter is not null, disposed of it
            // since we won't be using it

            if (_currentMediaSourceAdapter != null)
            {
                _currentMediaSourceAdapter.Dispose();
                _currentMediaSourceAdapter = null;
            }

            if (track.Song.IsStreaming)
            {
                _mediaPlayer.SetUriSource(new Uri(track.Song.AudioUrl));
            }
            else
            {
                var file = await StorageFile.GetFileFromPathAsync(track.Song.AudioUrl);

                if (file != null)
                {
                    try
                    {
                        if (file.FileType != ".flac")
                        {
                            _mediaPlayer.SetFileSource(file);
                        }
                        else
                        {
                            // Use custom media source for FLAC support
                            _currentMediaSourceAdapter =
                                await FlacMediaSourceAdapter.CreateAsync(file);
                            BackgroundMediaPlayer.Current.SetMediaSource(_currentMediaSourceAdapter.MediaSource);
                        }
                    }
                    catch
                    {
                        SkipToNext();
                    }
                }
                else if (CurrentTrack.NextId != 0 && CurrentTrack.PrevId != 0)
                    SkipToNext();
            }
            _mediaPlayer.Play();
        }