コード例 #1
0
ファイル: Track.cs プロジェクト: Jc54/PlayMe
 internal TrackWrapper(Track track)
 {
     this.track = track;
 }
コード例 #2
0
ファイル: Track.cs プロジェクト: Jc54/PlayMe
 protected override void OnDispose()
 {
     Track.Delete(track.trackPtr);
     track = null;
 }
コード例 #3
0
ファイル: Playlist.cs プロジェクト: McBainUK/SpotiFire
        protected Playlist(Session session, IntPtr playlistPtr, bool registerCallbacks = true)
        {
            if (playlistPtr == IntPtr.Zero)
            {
                throw new ArgumentException("playlistPtr can't be zero.");
            }

            if (session == null)
            {
                throw new ArgumentNullException("Session can't be null.");
            }

            this.session           = session;
            this.playlistPtr       = playlistPtr;
            this.registerCallbacks = registerCallbacks;

            if (registerCallbacks)
            {
                tracks_added                = new tracks_added_cb(TracksAddedCallback);
                tracks_removed              = new tracks_removed_cb(TracksRemovedCallback);
                tracks_moved                = new tracks_moved_cd(TracksMovedCallback);
                playlist_renamed            = new playlist_renamed_cb(RenamedCallback);
                playlist_state_changed      = new playlist_state_changed_cb(StateChangedCallback);
                playlist_update_in_progress = new playlist_update_in_progress_cb(UpdateInProgressCallback);
                playlist_metadata_updated   = new playlist_metadata_updated_cb(MetadataUpdatedCallback);
                track_created_changed       = new track_created_changed_cb(TrackCreatedChangedCallback);
                track_seen_changed          = new track_seen_changed_cb(TrackSeenChangedCallback);
                description_changed         = new description_changed_cb(DescriptionChangedCallback);
                image_changed               = new image_changed_cb(ImageChangedCallback);
                sp_playlist_callbacks callbacks = new sp_playlist_callbacks
                {
                    tracks_added                = Marshal.GetFunctionPointerForDelegate(tracks_added),
                    tracks_removed              = Marshal.GetFunctionPointerForDelegate(tracks_removed),
                    tracks_moved                = Marshal.GetFunctionPointerForDelegate(tracks_moved),
                    playlist_renamed            = Marshal.GetFunctionPointerForDelegate(playlist_renamed),
                    playlist_state_changed      = Marshal.GetFunctionPointerForDelegate(playlist_state_changed),
                    playlist_update_in_progress = Marshal.GetFunctionPointerForDelegate(playlist_update_in_progress),
                    playlist_metadata_updated   = Marshal.GetFunctionPointerForDelegate(playlist_metadata_updated),
                    track_created_changed       = Marshal.GetFunctionPointerForDelegate(track_created_changed),
                    track_seen_changed          = Marshal.GetFunctionPointerForDelegate(track_seen_changed),
                    description_changed         = Marshal.GetFunctionPointerForDelegate(description_changed),
                    image_changed               = Marshal.GetFunctionPointerForDelegate(image_changed)
                };

                callbacksPtr = Marshal.AllocHGlobal(Marshal.SizeOf(callbacks));
                Marshal.StructureToPtr(callbacks, callbacksPtr, true);
            }

            lock (libspotify.Mutex)
            {
                libspotify.sp_playlist_add_ref(playlistPtr);
                if (registerCallbacks)
                {
                    libspotify.sp_playlist_add_callbacks(playlistPtr, callbacksPtr, IntPtr.Zero);
                }
            }

            session.DisposeAll += new SessionEventHandler(session_DisposeAll);

            tracks = new PlaylistTrackList(
                () =>
            {
                IsAlive(true);
                lock (libspotify.Mutex)
                    return(libspotify.sp_playlist_num_tracks(playlistPtr));
            },
                (index) =>
            {
                IsAlive(true);
                lock (libspotify.Mutex)
                    return(PlaylistTrack.Get(session, this, libspotify.sp_playlist_track(playlistPtr, index), index));
            },
                (track, index) =>
            {
                IsAlive(true);
                IntPtr trackArrayPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)));
                IntPtr[] ptrArray    = new[] { Track.GetPointer(track) };

                try
                {
                    Marshal.Copy(ptrArray, 0, trackArrayPtr, 1);

                    lock (libspotify.Mutex)
                        libspotify.sp_playlist_add_tracks(playlistPtr, trackArrayPtr, 1, index, session.sessionPtr);
                }
                finally
                {
                    try { Marshal.FreeHGlobal(trackArrayPtr); }
                    catch
                    {}
                }
            },
                (index) =>
            {
                IsAlive(true);
                lock (libspotify.Mutex)
                    libspotify.sp_playlist_remove_tracks(playlistPtr, new int[] { index }, 1);
            },
                () => false
                );
            PlaylistTrack.RegisterPlaylist(this);
        }