protected override void AddTrackToDevice (DatabaseTrackInfo track, SafeUri fromUri) { if (track.PrimarySourceId == DbId) return; lock (mtp_device) { Track mtp_track = TrackInfoToMtpTrack (track, fromUri); bool video = track.HasAttribute (TrackMediaAttributes.VideoStream); mtp_device.UploadTrack (fromUri.LocalPath, mtp_track, GetFolderForTrack (track), OnUploadProgress); // Add/update album art if (!video) { string key = MakeAlbumKey (track.AlbumArtist, track.AlbumTitle); if (!album_cache.ContainsKey (key)) { // LIBMTP 1.0.3 BUG WORKAROUND // In libmtp.c the 'LIBMTP_Create_New_Album' function invokes 'create_new_abstract_list'. // The latter calls strlen on the 'name' parameter without null checking. If AlbumTitle is // null, this causes a sigsegv. Lets be safe and always pass non-null values. Album album = new Album (mtp_device, track.AlbumTitle ?? "", track.AlbumArtist ?? "", track.Genre ?? "", track.Composer ?? ""); album.AddTrack (mtp_track); if (supports_jpegs && can_sync_albumart) { try { Gdk.Pixbuf pic = ServiceManager.Get<Banshee.Collection.Gui.ArtworkManager> ().LookupScalePixbuf ( track.ArtworkId, thumb_width ); if (pic != null) { byte [] bytes = pic.SaveToBuffer ("jpeg"); album.Save (bytes, (uint)pic.Width, (uint)pic.Height); Banshee.Collection.Gui.ArtworkManager.DisposePixbuf (pic); } album_cache[key] = album; } catch (Exception e) { Log.Debug ("Failed to create MTP Album", e.Message); } } else { album.Save (); album_cache[key] = album; } } else { Album album = album_cache[key]; album.AddTrack (mtp_track); album.Save (); } } MtpTrackInfo new_track = new MtpTrackInfo (mtp_device, mtp_track); new_track.PrimarySource = this; new_track.Save (false); track_map[new_track.TrackId] = mtp_track; } }
protected override void AddTrackToDevice (DatabaseTrackInfo track, SafeUri fromUri) { if (track.PrimarySourceId == DbId) return; lock (mtp_device) { Track mtp_track = TrackInfoToMtpTrack (track, fromUri); bool video = track.HasAttribute (TrackMediaAttributes.VideoStream); mtp_device.UploadTrack (fromUri.LocalPath, mtp_track, GetFolderForTrack (track), OnUploadProgress); // Add/update album art if (!video) { string key = MakeAlbumKey (track.AlbumArtist, track.AlbumTitle); if (!album_cache.ContainsKey (key)) { Album album = new Album (mtp_device, track.AlbumTitle, track.AlbumArtist, track.Genre, track.Composer); album.AddTrack (mtp_track); if (supports_jpegs && can_sync_albumart) { try { Gdk.Pixbuf pic = ServiceManager.Get<Banshee.Collection.Gui.ArtworkManager> ().LookupScalePixbuf ( track.ArtworkId, thumb_width ); if (pic != null) { byte [] bytes = pic.SaveToBuffer ("jpeg"); album.Save (bytes, (uint)pic.Width, (uint)pic.Height); Banshee.Collection.Gui.ArtworkManager.DisposePixbuf (pic); } album_cache[key] = album; } catch (Exception e) { Log.Debug ("Failed to create MTP Album", e.Message); } } else { album.Save (); album_cache[key] = album; } } else { Album album = album_cache[key]; album.AddTrack (mtp_track); album.Save (); } } MtpTrackInfo new_track = new MtpTrackInfo (mtp_device, mtp_track); new_track.PrimarySource = this; new_track.Save (false); track_map[new_track.TrackId] = mtp_track; } }
public static Album GetById (MtpDevice device, uint id) { IntPtr ptr = Album.LIBMTP_Get_Album (device.Handle, id); if (ptr == IntPtr.Zero) { return null; } else { // Destroy the struct after we use it to prevent accessing freed memory // in the 'tracks' variable AlbumStruct album = (AlbumStruct) Marshal.PtrToStructure(ptr, typeof (AlbumStruct)); var ret = new Album (device, album); LIBMTP_destroy_album_t (ptr); return ret; } }
public List <Album> GetAlbums() { return(Album.GetAlbums(this)); }