public SongGridViewItem() { PlaylistItemId = Guid.Empty; IsSelected = false; IsMouseOverItem = false; IsEmptyRow = false; AudioFile = null; AlbumArtKey = string.Empty; }
public void RefreshCloudDeviceInfo(CloudDeviceInfo info, AudioFile audioFile) { Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { lblDeviceName.Content = info.DeviceName; lblArtistName.Content = audioFile.ArtistName; lblAlbumTitle.Content = audioFile.AlbumTitle; lblSongTitle.Content = audioFile.Title; lblLastUpdated.Content = string.Format("Last updated: {0}", info.Timestamp); imageAlbum.Source = null; var task = Task<BitmapImage>.Factory.StartNew(() => { try { var bytes = AudioFile.ExtractImageByteArrayForAudioFile(audioFile.FilePath); var stream = new MemoryStream(bytes); stream.Seek(0, SeekOrigin.Begin); var bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.StreamSource = stream; bitmap.EndInit(); bitmap.Freeze(); return bitmap; } catch (Exception ex) { Console.WriteLine("An error occured while extracing album art in {0}: {1}", audioFile.FilePath, ex); } return null; }); var imageResult = task.Result; if (imageResult != null) { Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { imageAlbum.Source = imageResult; })); } })); }
private void DrawCell(IGraphicsContext context, int row, int col, AudioFile audioFile, DrawCellState state) { var rect = new BasicRectangle(); var brush = new BasicBrush(); var brushGradient = new BasicGradientBrush(); var penTransparent = new BasicPen(); var column = _songCache.ActiveColumns[col]; if (column.Visible) { if (column.Title == "Now Playing") { // Draw now playing icon if ((_mode == SongGridViewMode.AudioFile && audioFile != null && audioFile.Id == _nowPlayingAudioFileId) || (_mode == SongGridViewMode.Playlist && _items[row].PlaylistItemId == _nowPlayingPlaylistItemId)) { // Which size is the minimum? Width or height? int availableWidthHeight = column.Width - 4; if (_songCache.LineHeight <= column.Width) availableWidthHeight = _songCache.LineHeight - 4; else availableWidthHeight = column.Width - 4; // Calculate the icon position float iconNowPlayingX = ((column.Width - availableWidthHeight) / 2) + state.OffsetX - HorizontalScrollBar.Value; float iconNowPlayingY = state.OffsetY + ((_songCache.LineHeight - availableWidthHeight) / 2); // Create NowPlaying rect (MUST be in integer) _rectNowPlaying = new BasicRectangle((int)iconNowPlayingX, (int)iconNowPlayingY, availableWidthHeight, availableWidthHeight); state.NowPlayingSongFound = true; // Draw outer circle brushGradient = new BasicGradientBrush(_theme.NowPlayingIndicatorBackgroundColor, _theme.NowPlayingIndicatorBackgroundColor, _timerAnimationNowPlayingCount % 360); context.DrawEllipsis(_rectNowPlaying, brushGradient, penTransparent); // Draw inner circle rect = new BasicRectangle((int)iconNowPlayingX + 4, (int)iconNowPlayingY + 4, availableWidthHeight - 8, availableWidthHeight - 8); brush = new BasicBrush(_theme.NowPlayingBackgroundColor); context.DrawEllipsis(rect, brush, penTransparent); } } else if (column.Title == "Album Cover") { DrawAlbumCoverZone(context, row, audioFile, state); } else if (audioFile != null) { // Print value depending on type var propertyInfo = audioFile.GetType().GetProperty(column.FieldName); if (propertyInfo != null) { string value = string.Empty; try { if (propertyInfo.PropertyType.FullName == "System.String") { value = propertyInfo.GetValue(audioFile, null).ToString(); } else if (propertyInfo.PropertyType.FullName.Contains("Int64") && propertyInfo.PropertyType.FullName.Contains("Nullable")) { long? longValue = (long?)propertyInfo.GetValue(audioFile, null); if (longValue.HasValue) value = longValue.Value.ToString(); } else if (propertyInfo.PropertyType.FullName.Contains("DateTime") && propertyInfo.PropertyType.FullName.Contains("Nullable")) { DateTime? dateTimeValue = (DateTime?)propertyInfo.GetValue(audioFile, null); if (dateTimeValue.HasValue) value = dateTimeValue.Value.ToShortDateString() + " " + dateTimeValue.Value.ToShortTimeString(); } else if (propertyInfo.PropertyType.FullName.Contains("System.UInt32")) { uint uintValue = (uint)propertyInfo.GetValue(audioFile, null); value = uintValue.ToString(); } else if (propertyInfo.PropertyType.FullName.Contains("System.Int32")) { int intValue = (int)propertyInfo.GetValue(audioFile, null); value = intValue.ToString(); } else if (propertyInfo.PropertyType.FullName.Contains("Sessions.Sound.AudioFileFormat")) { AudioFileFormat theValue = (AudioFileFormat)propertyInfo.GetValue(audioFile, null); value = theValue.ToString(); } } catch { // Do nothing } //// The last column always take the remaining width //int columnWidth = column.Width; //if (b == _songCache.ActiveColumns.Count - 1) //{ // // Calculate the remaining width // int columnsWidth = 0; // for (int c = 0; c < _songCache.ActiveColumns.Count - 1; c++) // { // columnsWidth += _songCache.ActiveColumns[c].Width; // } // //columnWidth = (int) (Frame.Width - columnsWidth + HorizontalScrollBar.Value); //} // Display text rect = new BasicRectangle(state.OffsetX - HorizontalScrollBar.Value + 2, state.OffsetY + (_theme.Padding / 2), _songCache.ActiveColumns[col].Width, _songCache.LineHeight - _theme.Padding + 2); //stringFormat.Trimming = StringTrimming.EllipsisCharacter; //stringFormat.Alignment = StringAlignment.Near; // Use bold for ArtistName and DiscTrackNumber if (column.FieldName == "ArtistName" || column.FieldName == "DiscTrackNumber") context.DrawText(value, rect, _theme.TextColor, _theme.FontNameBold, _theme.FontSize); else context.DrawText(value, rect, _theme.TextColor, _theme.FontName, _theme.FontSize); } } state.OffsetX += column.Width; } }
private void GetAlbumArt(AudioFile audioFile) { // TODO: Move this to PlayerStatusPresenter _bitmapAlbumArt = null; Task.Factory.StartNew(() => { Console.WriteLine("LockScreenActivity - GetAlbumArt - audioFile.Path: {0}", audioFile.FilePath); string key = audioFile.ArtistName + "_" + audioFile.AlbumTitle; if (string.IsNullOrEmpty(_previousAlbumArtKey) || _previousAlbumArtKey.ToUpper() != key.ToUpper()) { Console.WriteLine("LockScreenActivity - GetAlbumArt - key: {0} is different than tag {1} - Fetching album art...", key, _previousAlbumArtKey); _previousAlbumArtKey = key; byte[] bytesImage = AudioFile.ExtractImageByteArrayForAudioFile(audioFile.FilePath); if (bytesImage.Length == 0) { Console.WriteLine("LockScreenActivity - GetAlbumArt - Setting album art to NULL!"); RunOnUiThread(() => _imageAlbum.SetImageBitmap(_bitmapAlbumArt)); } else { Console.WriteLine("LockScreenActivity - GetAlbumArt - Getting album art in another thread..."); _bitmapCache.LoadBitmapFromByteArray(bytesImage, key, bitmap => { Console.WriteLine("WidgetService - GetAlbumArt - RECEIVED ALBUM ART! SETTING ALBUM ART"); _bitmapAlbumArt = bitmap; RunOnUiThread(() => _imageAlbum.SetImageBitmap(_bitmapAlbumArt)); }); } } }); }
public void LoadPeakFile(AudioFile audioFile) { _control.LoadPeakFile(audioFile); }
public void RefreshAudioFile(AudioFile audioFile) { RunOnUiThread(() => { // Make sure the UI is available if (_lblArtistName != null && audioFile != null) { _lblArtistName.Text = audioFile.ArtistName; _lblAlbumTitle.Text = audioFile.AlbumTitle; _lblSongTitle.Text = audioFile.Title; //if (message.Data.NextAudioFile != null) //{ // _lblNextArtistName.Text = message.Data.NextAudioFile.ArtistName; // _lblNextAlbumTitle.Text = message.Data.NextAudioFile.AlbumTitle; // _lblNextSongTitle.Text = message.Data.NextAudioFile.Title; //} //else //{ // _lblNextArtistName.Text = string.Empty; // _lblNextAlbumTitle.Text = string.Empty; // _lblNextSongTitle.Text = string.Empty; //} Task.Factory.StartNew(() => { string key = audioFile.ArtistName + "_" + audioFile.AlbumTitle; //Console.WriteLine("MainActivity - Player Bar - key: {0}", key); if (_imageAlbum.Tag == null || _imageAlbum.Tag.ToString().ToUpper() != key.ToUpper()) { //Console.WriteLine("MainActivity - Player Bar - key: {0} is different than tag {1} - Fetching album art...", key, (_imageAlbum.Tag == null) ? "null" : _imageAlbum.Tag.ToString()); _imageAlbum.Tag = key; byte[] bytesImage = AudioFile.ExtractImageByteArrayForAudioFile(audioFile.FilePath); if (bytesImage.Length == 0) _imageAlbum.SetImageBitmap(null); else BitmapCache.LoadBitmapFromByteArray(bytesImage, key, _imageAlbum); } }); } }); }
public void RefreshMarker(Marker marker, AudioFile audioFile) { _currentMarker = marker; Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { txtMarkerName.Text = marker.Name; lblMarkerPosition.Content = marker.Position; trackMarkerPosition.ValueWithoutEvent = (int)(marker.PositionPercentage * 10); scrollViewWaveForm.SetActiveMarker(marker.MarkerId); })); }
/// <summary> /// Plays the list of audio files specified in the filePaths parameter. /// </summary> /// <param name="filePaths">List of audio file paths</param> public void PlayFiles(List<string> filePaths) { // Create instances of the AudioFile class, but do not read metadata right now List<AudioFile> audioFiles = new List<AudioFile>(); foreach (string filePath in filePaths) { AudioFile audioFile = new AudioFile(filePath, Guid.NewGuid(), false); audioFiles.Add(audioFile); } PlayFiles(audioFiles); }
public void LoadPeakFile(AudioFile audioFile) { //Console.WriteLine("WaveFormControl - LoadPeakFile " + audioFile.FilePath); IsLoading = true; IsEmpty = false; AudioFile = audioFile; RefreshStatus("Loading peak file..."); _waveFormCacheService.LoadPeakFile(audioFile); }
public void RefreshSongInformation(AudioFile audioFile, long lengthBytes, int playlistIndex, int playlistCount) { Gtk.Application.Invoke(delegate{ if(audioFile != null) { // Refresh labels Console.WriteLine("MainWindow - RefreshSongInformation"); lblArtistName.Text = audioFile.ArtistName; lblAlbumTitle.Text = audioFile.AlbumTitle; lblSongTitle.Text = audioFile.Title; lblSongFilePath.Text = audioFile.FilePath; //lblCurrentPosition.Text = audioFile.Position; lblCurrentLength.Text = audioFile.Length; lblCurrentFileType.Text = audioFile.FileType.ToString(); lblCurrentBitrate.Text = audioFile.Bitrate.ToString(); lblCurrentSampleRate.Text = audioFile.SampleRate.ToString(); lblCurrentBitsPerSample.Text = audioFile.BitsPerSample.ToString(); //Pixbuf stuff = new Pixbuf("icon48.png"); //stuff = stuff.ScaleSimple(150, 150, InterpType.Bilinear); //imageAlbumCover.Pixbuf = stuff; System.Drawing.Image drawingImage = AudioFile.ExtractImageForAudioFile(audioFile.FilePath); if(drawingImage != null) { // Resize image and set cover drawingImage = SystemDrawingHelper.ResizeImage(drawingImage, 150, 150); imageAlbumCover.Pixbuf = ImageToPixbuf(drawingImage); } else { // Get Unix-style directory information (i.e. case sensitive file names) if(!String.IsNullOrEmpty(audioFile.FilePath)) { try { bool imageFound = false; string folderPath = System.IO.Path.GetDirectoryName(audioFile.FilePath); UnixDirectoryInfo rootDirectoryInfo = new UnixDirectoryInfo(folderPath); // For each directory, search for new directories UnixFileSystemInfo[] infos = rootDirectoryInfo.GetFileSystemEntries(); foreach (UnixFileSystemInfo fileInfo in rootDirectoryInfo.GetFileSystemEntries()) { // Check if the file matches string fileName = fileInfo.Name.ToUpper(); if((fileName.EndsWith(".JPG") || fileName.EndsWith(".JPEG") || fileName.EndsWith(".PNG") || fileName.EndsWith(".GIF")) && (fileName.StartsWith("FOLDER") || fileName.StartsWith("COVER"))) { // Get image from file imageFound = true; Pixbuf imageCover = new Pixbuf(fileInfo.FullName); imageCover = imageCover.ScaleSimple(150, 150, InterpType.Bilinear); imageAlbumCover.Pixbuf = imageCover; } } // Set empty image if not cover not found if(!imageFound) imageAlbumCover.Pixbuf = null; } catch { imageAlbumCover.Pixbuf = null; } } else { // Set empty album cover imageAlbumCover.Pixbuf = null; } } // Check if image cover is still empty if(imageAlbumCover.Pixbuf == null) { Pixbuf imageCover = ResourceHelper.GetEmbeddedImageResource("black.png"); imageCover = imageCover.ScaleSimple(150, 150, InterpType.Bilinear); imageAlbumCover.Pixbuf = imageCover; } } }); }
public void LoadPeakFile(AudioFile audioFile) { _zoom = 1; WaveView.ContentOffset = new BasicPoint(0, 0); WaveView.Zoom = 1; ScaleView.ContentOffset = new BasicPoint(0, 0); ScaleView.Zoom = 1; WaveView.LoadPeakFile(audioFile); ScaleView.AudioFile = audioFile; ScaleView.Invalidate(); }
public void LoadPeakFile(AudioFile audioFile) { WaveFormView.LoadPeakFile(audioFile); WaveFormScaleView.AudioFile = audioFile; WaveFormView.ContentOffset.X = 0; WaveFormView.Zoom = 1; WaveFormScaleView.ContentOffset.X = 0; WaveFormScaleView.Zoom = 1; }
private void Initialize() { Console.WriteLine("WidgetService - Initializing service..."); int maxMemory = (int) (Runtime.GetRuntime().MaxMemory()/1024); int cacheSize = maxMemory/16; _bitmapCache = new BitmapCache(null, cacheSize, 200, 200); _messengerHub = Bootstrapper.GetContainer().Resolve<ITinyMessengerHub>(); _playerService = Bootstrapper.GetContainer().Resolve<IPlayerService>(); _messengerHub.Subscribe<PlayerPlaylistIndexChangedMessage>((message) => { Console.WriteLine("WidgetService - PlayerPlaylistIndexChangedMessage"); if (message.Data.AudioFileStarted != null) { _audioFile = message.Data.AudioFileStarted; //UpdateNotificationView(message.Data.AudioFileStarted, null); UpdateWidgetView(); GetAlbumArt(message.Data.AudioFileStarted); } }); _messengerHub.Subscribe<PlayerStatusMessage>((message) => { Console.WriteLine("WidgetService - PlayerStatusMessage - Status=" + message.Status.ToString()); _status = message.Status; UpdateWidgetView(); }); }
private void GetAlbumArt(AudioFile audioFile) { _bitmapAlbumArt = null; Task.Factory.StartNew(() => { //Console.WriteLine("WidgetService - GetAlbumArt - audioFile.Path: {0}", audioFile.FilePath); string key = audioFile.ArtistName + "_" + audioFile.AlbumTitle; Console.WriteLine("MobileLibraryFragment - Album art - key: {0}", key); if (string.IsNullOrEmpty(_previousAlbumArtKey) || _previousAlbumArtKey.ToUpper() != key.ToUpper()) { //Console.WriteLine("WidgetService - GetAlbumArt - key: {0} is different than tag {1} - Fetching album art...", key, _previousAlbumArtKey); _previousAlbumArtKey = key; byte[] bytesImage = AudioFile.ExtractImageByteArrayForAudioFile(audioFile.FilePath); if (bytesImage.Length == 0) //_imageAlbum.SetImageBitmap(null); { //Console.WriteLine("WidgetService - GetAlbumArt - Setting album art to NULL!"); UpdateWidgetView(); } else { //((MainActivity)Activity).BitmapCache.LoadBitmapFromByteArray(bytesImage, key, _imageAlbum); //_bitmapCache.LoadBitmapFromByteArray(bytesImage, key, _imageAlbum); //Console.WriteLine("WidgetService - GetAlbumArt - Getting album art in another thread..."); _bitmapCache.LoadBitmapFromByteArray(bytesImage, key, bitmap => { Console.WriteLine("WidgetService - GetAlbumArt - RECEIVED ALBUM ART! SETTING ALBUM ART"); _bitmapAlbumArt = bitmap; UpdateWidgetView(); }); } } }); }
public void RefreshCloudDeviceInfo(CloudDeviceInfo info, AudioFile audioFile) { Activity.RunOnUiThread(() => { _lblDeviceName.Text = info.DeviceName; _lblPlaylistName.Text = "On-the-fly playlist"; _lblArtistName.Text = info.ArtistName; _lblAlbumTitle.Text = info.AlbumTitle; _lblSongTitle.Text = info.SongTitle; _lblTimestamp.Text = string.Format("Last updated: {0} {1}", info.Timestamp.ToShortDateString(), info.Timestamp.ToLongTimeString()); }); }
public void RefreshCurrentlyPlayingSong(int index, AudioFile audioFile) { Console.WriteLine("PlaylistActivity - RefreshCurrentlyPlayingSong index: {0} audioFile: {1}", index, audioFile.FilePath); RunOnUiThread(() => { _itemListAdapter.SetNowPlayingRow(index, audioFile); }); }
public void RefreshSongInformation(AudioFile audioFile, long lengthBytes, int playlistIndex, int playlistCount) { RunOnUiThread(() => { if (audioFile == null) return; _lblLength.Text = audioFile.Length; ActionBar.Title = audioFile.ArtistName; Task.Factory.StartNew(() => { string key = audioFile.ArtistName + "_" + audioFile.AlbumTitle; //Console.WriteLine("PlayerActivity - Album art - key: {0}", key); if (_imageViewAlbumArt.Tag == null || _imageViewAlbumArt.Tag.ToString().ToUpper() != key.ToUpper()) { //Console.WriteLine("PlayerActivity - Album art - key: {0} is different than tag {1} - Fetching album art...", key, (_imageViewAlbumArt.Tag == null) ? "null" : _imageViewAlbumArt.Tag.ToString()); _imageViewAlbumArt.Tag = key; byte[] bytesImage = AudioFile.ExtractImageByteArrayForAudioFile(audioFile.FilePath); if (bytesImage.Length == 0) _imageViewAlbumArt.SetImageBitmap(null); else _bitmapCache.LoadBitmapFromByteArray(bytesImage, key, _imageViewAlbumArt); } }); _waveFormScrollView.SetWaveFormLength(lengthBytes); _waveFormScrollView.LoadPeakFile(audioFile); }); }
public void RefreshMarker(Marker marker, AudioFile audioFile) { InvokeOnMainThread(() => { _marker = marker; txtName.Text = marker.Name; textViewComments.Text = marker.Comments; //lblPosition.Text = marker.Position; lblLength.Text = audioFile.Length; }); }
public override IEditSongMetadataView CreateEditSongMetadataView(AudioFile audioFile) { IEditSongMetadataView view = null; using (var pool = new NSAutoreleasePool()) { pool.InvokeOnMainThread(delegate { view = base.CreateEditSongMetadataView(audioFile); }); } return view; }
public void RefreshMarker(Marker marker, AudioFile audioFile) { }
public void RefreshSongInformation(AudioFile audioFile, long lengthBytes, int playlistIndex, int playlistCount) { _selectedMarkerIndex = -1; _currentAudioFile = audioFile; Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() => { if (audioFile == null) { lblArtistName.Content = string.Empty; lblAlbumTitle.Content = string.Empty; lblSongTitle.Content = string.Empty; lblFilePath.Content = string.Empty; lblSampleRate.Content = string.Empty; lblBitrate.Content = string.Empty; lblBitsPerSample.Content = string.Empty; lblSoundFormat.Content = string.Empty; lblYear.Content = string.Empty; lblMonoStereo.Content = string.Empty; lblFileSize.Content = string.Empty; lblGenre.Content = string.Empty; lblPlayCount.Content = string.Empty; lblLastPlayed.Content = string.Empty; lblPosition.Content = "0:00.000"; lblLength.Content = "0:00.000"; _currentAlbumArtKey = string.Empty; imageAlbum.Source = null; scrollViewWaveForm.Reset(); outputMeter.Reset(); } else { lblArtistName.Content = audioFile.ArtistName; lblAlbumTitle.Content = audioFile.AlbumTitle; lblSongTitle.Content = audioFile.Title; lblFilePath.Content = audioFile.FilePath; lblLength.Content = audioFile.Length; lblSampleRate.Content = string.Format("{0} Hz", audioFile.SampleRate); lblBitrate.Content = string.Format("{0} kbps", audioFile.Bitrate); lblBitsPerSample.Content = string.Format("{0} bits", audioFile.BitsPerSample); lblSoundFormat.Content = audioFile.FileType.ToString(); lblYear.Content = audioFile.Year == 0 ? "No year specified" : audioFile.Year.ToString(); lblMonoStereo.Content = audioFile.AudioChannels == 1 ? "Mono" : "Stereo"; lblFileSize.Content = string.Format("{0} bytes", audioFile.FileSize); lblGenre.Content = string.IsNullOrEmpty(audioFile.Genre) ? "No genre specified" : string.Format("{0}", audioFile.Genre); lblPlayCount.Content = string.Format("{0} times played", audioFile.PlayCount); lblLastPlayed.Content = audioFile.LastPlayed.HasValue ? string.Format("Last played on {0}", audioFile.LastPlayed.Value.ToShortDateString()) : ""; // miTrayArtistName.Text = audioFile.ArtistName; // miTrayAlbumTitle.Text = audioFile.AlbumTitle; // miTraySongTitle.Text = audioFile.Title; gridViewSongsNew.NowPlayingAudioFileId = audioFile.Id; scrollViewWaveForm.SetWaveFormLength(lengthBytes); scrollViewWaveForm.LoadPeakFile(audioFile); string key = audioFile.ArtistName.ToUpper() + "_" + audioFile.AlbumTitle.ToUpper(); if (_currentAlbumArtKey != key) { imageAlbum.Source = null; var task = Task<BitmapImage>.Factory.StartNew(() => { try { var bytes = AudioFile.ExtractImageByteArrayForAudioFile(audioFile.FilePath); var stream = new MemoryStream(bytes); stream.Seek(0, SeekOrigin.Begin); var bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.StreamSource = stream; bitmap.EndInit(); bitmap.Freeze(); return bitmap; } catch (Exception ex) { Console.WriteLine("An error occured while extracing album art in {0}: {1}", audioFile.FilePath, ex); } return null; }); var imageResult = task.Result; if (imageResult != null) { _currentAlbumArtKey = key; Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { imageAlbum.Source = imageResult; })); } } } })); }
private async void LoadAlbumArt(AudioFile audioFile) { var task = Task<NSImage>.Factory.StartNew(() => { try { NSImage image = null; byte[] bytesImage = AudioFile.ExtractImageByteArrayForAudioFile(audioFile.FilePath); using (NSData imageData = NSData.FromArray(bytesImage)) { InvokeOnMainThread(() => { image = new NSImage(imageData); }); } return image; } catch (Exception ex) { Console.WriteLine("PlayerViewController - RefreshSongInformation - Failed to process image: {0}", ex); } return null; }); NSImage imageFromTask = await task; if(imageFromTask == null) return; InvokeOnMainThread(() => { try { imageViewAlbum.Image = imageFromTask; } catch(Exception ex) { Console.WriteLine("PlayerViewController - RefreshSongInformation - Failed to set image after processing: {0}", ex); } }); }
public void RefreshLoopDetails(Loop loop, AudioFile audioFile) { _currentLoop = loop; Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() => { txtLoopName.Text = loop.Name; scrollViewWaveForm.SetLoop(loop); //scrollViewWaveForm.FocusZoomOnLoop(_currentLoop); listViewSegments.ItemsSource = _currentLoop.Segments; listViewSegments.SelectedIndex = _selectedSegmentIndex; })); }
public void RefreshCloudDeviceInfo(CloudDeviceInfo info, AudioFile audioFile) { InvokeOnMainThread(() => { lblDeviceName.StringValue = info.DeviceName; lblArtistName.StringValue = audioFile.ArtistName; lblAlbumTitle.StringValue = audioFile.AlbumTitle; lblSongTitle.StringValue = audioFile.Title; lblLastUpdated.StringValue = string.Format("Last updated: {0}", info.Timestamp); SyncDeviceType deviceType = SyncDeviceType.Unknown; Enum.TryParse<SyncDeviceType>(info.DeviceType, out deviceType); LoadDeviceIcon(deviceType); LoadAlbumArt(audioFile); }); }
public void LoadPeakFile(AudioFile audioFile) { FlushCache(); _waveFormRenderingService.LoadPeakFile(audioFile); }
public async void RefreshCloudDeviceInfo(CloudDeviceInfo device, AudioFile audioFile) { InvokeOnMainThread(() => { lblDeviceName.Text = device.DeviceName; lblPlaylistName.Text = "On-the-fly Playlist"; lblArtistName.Text = device.ArtistName; lblAlbumTitle.Text = device.AlbumTitle; lblSongTitle.Text = device.SongTitle; lblTimestamp.Text = string.Format("Last updated: {0} {1}", device.Timestamp.ToShortDateString(), device.Timestamp.ToLongTimeString()); }); int height = 44; InvokeOnMainThread(() => { try { height = (int)(imageAlbum.Bounds.Height * UIScreen.MainScreen.Scale); UIView.Animate(0.3, () => { imageAlbum.Alpha = 0; }); } catch(Exception ex) { Console.WriteLine("PlayerViewController - RefreshSongInformation - Failed to set image view album art alpha: {0}", ex); } }); // Load album art + resize in another thread var task = Task<UIImage>.Factory.StartNew(() => { try { byte[] bytesImage = AudioFile.ExtractImageByteArrayForAudioFile(audioFile.FilePath); using (NSData imageData = NSData.FromArray(bytesImage)) { using (UIImage imageFullSize = UIImage.LoadFromData(imageData)) { if (imageFullSize != null) { try { UIImage imageResized = CoreGraphicsHelper.ScaleImage(imageFullSize, height); return imageResized; } catch (Exception ex) { Console.WriteLine("Error resizing image " + audioFile.ArtistName + " - " + audioFile.AlbumTitle + ": " + ex.Message); } } } } } catch (Exception ex) { Console.WriteLine("StartResumePlaybackViewController - RefreshCloudDeviceInfo - Failed to process image: {0}", ex); } return null; }); //}).ContinueWith(t => { UIImage image = await task; if(image == null) return; InvokeOnMainThread(() => { try { imageAlbum.Alpha = 0; imageAlbum.Image = image; UIView.Animate(0.3, () => { imageAlbum.Alpha = 1; }); } catch(Exception ex) { Console.WriteLine("StartResumePlaybackViewController - RefreshCloudDeviceInfo - Failed to set image after processing: {0}", ex); } }); //}, TaskScheduler.FromCurrentSynchronizationContext()); }
public void LoadPeakFile(AudioFile audioFile) { //WaveFormScaleView.Hidden = true; //UserInteractionEnabled = false; if(ScrollViewMode == WaveFormScrollViewMode.Standard) { WaveFormView.Frame = new RectangleF(0, _scaleHeight, Bounds.Width, Bounds.Height - _scaleHeight); WaveFormScaleView.Frame = new RectangleF(0, 0, Bounds.Width, _scaleHeight); } else if(ScrollViewMode == WaveFormScrollViewMode.SelectPosition) { WaveFormView.Frame = new RectangleF(Bounds.Width / 2, _scaleHeight, Bounds.Width, Bounds.Height - _scaleHeight); WaveFormScaleView.Frame = new RectangleF(Bounds.Width / 2, 0, Bounds.Width, _scaleHeight); } WaveFormView.LoadPeakFile(audioFile); WaveFormScaleView.AudioFile = audioFile; WaveFormScaleView.SetNeedsDisplay(); }
public void LoadPeakFile(AudioFile audioFile) { // Check if another peak file is already loading Console.WriteLine("WaveFormRenderingService - LoadPeakFile audioFile: " + audioFile.FilePath); _audioFile = audioFile; if (_peakFileService.IsLoading) { //Console.WriteLine("WaveFormRenderingService - Cancelling current peak file generation..."); _peakFileService.Cancel(); } // Check if the peak file subfolder exists string peakFileFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "PeakFiles"); if (!Directory.Exists(peakFileFolder)) { try { //Console.WriteLine("WaveFormRenderingService - Creating folder " + peakFileFolder + "..."); Directory.CreateDirectory(peakFileFolder); } catch (Exception ex) { Console.WriteLine("WaveFormRenderingService - Failed to create folder: " + ex.Message); return; } } // Generate peak file path string peakFilePath = Path.Combine(peakFileFolder, Normalizer.NormalizeStringForUrl(audioFile.ArtistName + "_" + audioFile.AlbumTitle + "_" + audioFile.Title + "_" + audioFile.FileType.ToString()) + ".peak"); // Check if peak file exists if (File.Exists(peakFilePath)) { // TODO: This needs to be done in another thread with new Thread(), long running thread sucks SynchronizationContext.SetSynchronizationContext(new SynchronizationContext()); Task<List<WaveDataMinMax>>.Factory.StartNew(() => { List<WaveDataMinMax> data = null; FlushCache(); try { Console.WriteLine("WaveFormRenderingService - Reading peak file: " + peakFilePath); data = _peakFileService.ReadPeakFile(peakFilePath); if (data != null) return data; } catch (Exception ex) { Console.WriteLine("Error reading peak file: " + ex.Message); } try { Console.WriteLine("WaveFormRenderingService - Peak file could not be loaded - Generating " + peakFilePath + "..."); OnGeneratePeakFileBegun(new GeneratePeakFileEventArgs()); _peakFileService.GeneratePeakFile(audioFile.FilePath, peakFilePath); } catch (Exception ex) { Console.WriteLine("Error generating peak file: " + ex.Message); } return null; }, TaskCreationOptions.LongRunning).ContinueWith(t => { Console.WriteLine("WaveFormRenderingService - Read peak file over."); var data = (List<WaveDataMinMax>)t.Result; if (data == null) { //Console.WriteLine("WaveFormRenderingService - Could not load a peak file from disk (i.e. generating a new peak file)."); return; } Console.WriteLine("WaveFormRenderingService - Adding wave data to cache..."); _waveDataCache = data; OnLoadedPeakFileSuccessfully(new LoadPeakFileEventArgs() { AudioFile = audioFile }); }, TaskScheduler.FromCurrentSynchronizationContext()); } else { // Start generating peak file in background Console.WriteLine("Peak file doesn't exist - Generating " + peakFilePath + "..."); _peakFileService.GeneratePeakFile(audioFile.FilePath, peakFilePath); } }
public void RefreshAudioFile(AudioFile audioFile) { if (_lblArtistName == null) return; RunOnUiThread(() => { if (audioFile != null) { _lblArtistName.Text = audioFile.ArtistName; _lblAlbumTitle.Text = audioFile.AlbumTitle; _lblSongTitle.Text = audioFile.Title; _lblLength.Text = audioFile.Length; GetAlbumArt(audioFile); } else { _lblArtistName.Text = string.Empty; _lblAlbumTitle.Text = string.Empty; _lblSongTitle.Text = string.Empty; _lblLength.Text = string.Empty; } }); }
public void RefreshLoopDetails(Loop loop, AudioFile audioFile) { }