public override void Initialize() { _artist = new Lazy <IUser>(() => { AssertHandle(); lock (Spotify.Mutex) { return(UserManager.Get(Session, Spotify.sp_link_as_user(Handle))); } }); }
public override void Initialize() { _playlist = new Lazy <IPlaylist>(() => { AssertHandle(); lock (Spotify.Mutex) { return(PlaylistManager.Get(Session, Spotify.sp_playlist_create(Session.GetHandle(), Handle))); } }); }
private IContainerPlaylist GetPlaylistAtIndex(int index) { lock (Spotify.Mutex) { return(ContainerPlaylistManager.Get( Session, this, Spotify.sp_playlistcontainer_playlist(Handle, index), Spotify.sp_playlistcontainer_playlist_folder_id(Handle, index), Spotify.sp_playlistcontainer_playlist_type(Handle, index))); } }
public override void Initialize() { _album = new Lazy <IAlbum>( () => { AssertHandle(); lock (Spotify.Mutex) { return(AlbumManager.Get(Session, Spotify.sp_link_as_album(Handle))); } }); }
public void Login(string userName, string password, bool rememberMe = false) { AssertHandle(); lock (Spotify.Mutex) { Error error = Spotify.sp_session_login(Handle, userName, password, rememberMe, null); if (error != Error.OK) { throw new TorshifyException(error.GetMessage(), error); } } }
public void LoginWithBlob(string userName, string blob) { AssertHandle(); lock (Spotify.Mutex) { Error error = Spotify.sp_session_login(Handle, userName, null, false, blob); if (error != Error.OK) { throw new TorshifyException(error.GetMessage(), error); } } }
public void ForgetStoredLogin() { AssertHandle(); lock (Spotify.Mutex) { Error error = Spotify.sp_session_forget_me(Handle); if (error != Error.OK) { throw new TorshifyException(error.GetMessage(), error); } } }
public void Logout() { AssertHandle(); lock (Spotify.Mutex) { Error error = Spotify.sp_session_logout(Handle); if (error != Error.OK) { throw new TorshifyException(error.GetMessage(), error); } } }
private IPlaylistSearchResult GetPlaylistAtIndex(int index) { AssertHandle(); lock (Spotify.Mutex) { return(new NativePlaylistSearchResult { Name = Spotify.sp_search_playlist_name(Handle, index), ImageUri = Spotify.sp_search_playlist_image_uri(Handle, index), Uri = Spotify.sp_search_playlist_uri(Handle, index) }); } }
private void OnTrackSeenChangedCallback(IntPtr playlistPtr, int position, bool seen, IntPtr userdataptr) { if (playlistPtr != _playlist.Handle) { return; } ITrack track = PlaylistTrackManager.Get( _playlist.Session, _playlist, Spotify.sp_playlist_track(playlistPtr, position), position); _playlist.QueueThis(() => _playlist.OnTrackSeenChanged(new TrackSeenEventArgs(track, seen))); }
public IPlaylistContainer GetPlaylistContainerForUser(string canonicalUsername) { if (ConnectionState != ConnectionState.LoggedIn) { return(null); } AssertHandle(); lock (Spotify.Mutex) { IntPtr containerPtr = Spotify.sp_session_publishedcontainer_for_user_create(Handle, canonicalUsername); return(PlaylistContainerManager.Get(this, containerPtr)); } }
public IPlaylist GetStarredForUser(string canonicalUserName) { if (ConnectionState != ConnectionState.LoggedIn) { return(null); } AssertHandle(); lock (Spotify.Mutex) { IntPtr starredPtr = Spotify.sp_session_starred_for_user_create(Handle, canonicalUserName); return(PlaylistManager.Get(this, starredPtr)); } }
public ISession SetConnectionRules(ConnectionRule connectionRule) { AssertHandle(); lock (Spotify.Mutex) { Error error = Spotify.sp_session_set_connection_rules(Handle, connectionRule); if (error != Error.OK) { throw new TorshifyException(error.GetMessage(), error); } } return(this); }
public ISession SetPreferredOfflineBitrate(Bitrate bitrate, bool resync) { AssertHandle(); lock (Spotify.Mutex) { Error error = Spotify.sp_session_preferred_offline_bitrate(Handle, bitrate, resync); if (error != Error.OK) { throw new TorshifyException(error.GetMessage(), error); } } return(this); }
public void Dispose() { if (_registerCallbacks) { try { lock (Spotify.Mutex) { Spotify.sp_playlist_remove_callbacks(_playlist.Handle, ref _callbacks, IntPtr.Zero); } } catch { } } }
private IContainerPlaylist AddNewPlaylist(string name) { AssertHandle(); lock (Spotify.Mutex) { IntPtr playlistPtr = Spotify.sp_playlistcontainer_add_new_playlist(Handle, name); return(ContainerPlaylistManager.Get( Session, this, playlistPtr, IntPtr.Zero, PlaylistType.Playlist)); } }
private void AddNewTrack(ITrack track, int index) { IntPtr[] ptrArray = new[] { track.GetHandle() }; IntPtr trackArrayPtr = Marshal.AllocHGlobal(Marshal.SizeOf(ptrArray[0])); Marshal.Copy(ptrArray, 0, trackArrayPtr, 1); AssertHandle(); lock (Spotify.Mutex) { Spotify.sp_playlist_add_tracks(Handle, trackArrayPtr, 1, index, Session.GetHandle()); } Marshal.FreeHGlobal(trackArrayPtr); }
public ISession SetCacheSize(uint megabytes) { AssertHandle(); lock (Spotify.Mutex) { Error error = Spotify.sp_session_set_cache_size(Handle, megabytes); if (error != Error.OK) { throw new TorshifyException(error.GetMessage(), error); } } return(this); }
public Error PlayerPrefetch(ITrack track) { AssertHandle(); INativeObject nativeObject = track as INativeObject; if (nativeObject == null) { throw new ArgumentException("Invalid argument"); } lock (Spotify.Mutex) { return(Spotify.sp_session_player_prefetch(Handle, nativeObject.GetHandle())); } }
private void OnTrackCreatedChangedCallback(IntPtr playlistPtr, int position, IntPtr userptr, int when, IntPtr userdataptr) { if (playlistPtr != _playlist.Handle) { return; } ITrack track = PlaylistTrackManager.Get( _playlist.Session, _playlist, Spotify.sp_playlist_track(playlistPtr, position), position); DateTime dtWhen = new DateTime(TimeSpan.FromSeconds(when).Ticks, DateTimeKind.Utc); _playlist.QueueThis(() => _playlist.OnTrackCreatedChanged(new TrackCreatedChangedEventArgs(track, dtWhen))); }
public override void Initialize() { _artist = new Lazy <IArtist>(() => { AssertHandle(); lock (Spotify.Mutex) { return(ArtistManager.Get(Session, Spotify.sp_album_artist(Handle))); } }); lock (Spotify.Mutex) { Spotify.sp_album_add_ref(Handle); } }
private void OnPlaylistAddedCallback(IntPtr containerPointer, IntPtr playlistptr, int position, IntPtr userdataptr) { if (containerPointer != _container.Handle) { return; } var containerPlaylist = ContainerPlaylistManager.Get( _container.Session, _container, playlistptr, Spotify.sp_playlistcontainer_playlist_folder_id(containerPointer, position), Spotify.sp_playlistcontainer_playlist_type(containerPointer, position)); var args = new PlaylistEventArgs(containerPlaylist, position); _container.QueueThis(() => _container.OnPlaylistAdded(args)); }
private IContainerPlaylist AddExistingPlaylist(ILink <IPlaylist> link) { INativeObject nativeObject = (INativeObject)link; AssertHandle(); lock (Spotify.Mutex) { IntPtr playlistPtr = Spotify.sp_playlistcontainer_add_playlist(Handle, nativeObject.Handle); return(ContainerPlaylistManager.Get( Session, this, playlistPtr, IntPtr.Zero, PlaylistType.Playlist)); } }
public void Dispose() { try { lock (Spotify.Mutex) { Spotify.sp_playlistcontainer_remove_callbacks(_container.Handle, ref _callbacks, IntPtr.Zero); } } catch { // Ignore } finally { GC.KeepAlive(_callbacks); } }
public NativePlaylistContainerCallbacks(NativePlaylistContainer container) { _container = container; _playlistAdded = OnPlaylistAddedCallback; _playlistRemoved = OnPlaylistRemovedCallback; _playlistMoved = OnPlaylistMovedCallback; _containerLoaded = OnLoadedCallback; lock (Spotify.Mutex) { _callbacks = new PlaylistContainerCallbacks(); _callbacks.ContainerLoaded = Marshal.GetFunctionPointerForDelegate(_containerLoaded); _callbacks.PlaylistAdded = Marshal.GetFunctionPointerForDelegate(_playlistAdded); _callbacks.PlaylistMoved = Marshal.GetFunctionPointerForDelegate(_playlistMoved); _callbacks.PlaylistRemoved = Marshal.GetFunctionPointerForDelegate(_playlistRemoved); Spotify.sp_playlistcontainer_add_callbacks(container.Handle, ref _callbacks, IntPtr.Zero); } }
public override void Initialize() { _callbacks = new NativePlaylistCallbacks(this); _tracks = new Lazy <NativePlaylistTrackList>(() => new NativePlaylistTrackList( GetNumberOfTracks, GetTrackIndex, AddTrack, AddNewTrack, RemoveTrack, () => false, MoveTrack, MoveMultipleTracks)); lock (Spotify.Mutex) { Spotify.sp_playlist_add_ref(Handle); Spotify.sp_playlist_update_subscribers(Session.GetHandle(), Handle); } }
public override void Initialize() { _browseCompleteCallback = OnBrowseCompleteCallback; _tracks = new DelegateArray <ITrack>(GetNumberOfTracks, GetTrackAtIndex); _topHitTracks = new DelegateArray <ITrack>(GetNumberOfTopHitTracks, GetTopHitTrackAtIndex); _albums = new DelegateArray <IAlbum>(GetNumberOfAlbums, GetAlbumAtIndex); _similarArtists = new DelegateArray <IArtist>(GetNumberOfSimilarArtists, GetSimilarArtistAtIndex); _portraits = new DelegateArray <IImage>(GetNumberOfPortraits, GetPortraitAtIndex); lock (Spotify.Mutex) { Handle = Spotify.sp_artistbrowse_create( Session.GetHandle(), _artistToBrowse, _browseType, _browseCompleteCallback, IntPtr.Zero); } }
public NativePlaylistCallbacks(NativePlaylist playlist, bool registerCallbacks = true) { _registerCallbacks = registerCallbacks; _playlist = playlist; if (registerCallbacks) { _tracksAdded = OnTracksAddedCallback; _tracksRemoved = OnTracksRemovedCallback; _tracksMoved = OnTracksMovedCallback; _playlistRenamed = OnRenamedCallback; _playlistStateChanged = OnStateChangedCallback; _playlistUpdateInProgress = OnUpdateInProgressCallback; _playlistMetadataUpdated = OnMetadataUpdatedCallback; _trackCreatedChanged = OnTrackCreatedChangedCallback; _trackSeenChanged = OnTrackSeenChangedCallback; _descriptionChanged = OnDescriptionChangedCallback; _imageChanged = OnImageChangedCallback; _subscribersChanged = OnSubscribersChangedCallback; _callbacks = new Spotify.PlaylistCallbacks { tracks_added = Marshal.GetFunctionPointerForDelegate(_tracksAdded), tracks_removed = Marshal.GetFunctionPointerForDelegate(_tracksRemoved), tracks_moved = Marshal.GetFunctionPointerForDelegate(_tracksMoved), playlist_renamed = Marshal.GetFunctionPointerForDelegate(_playlistRenamed), playlist_state_changed = Marshal.GetFunctionPointerForDelegate(_playlistStateChanged), playlist_update_in_progress = Marshal.GetFunctionPointerForDelegate(_playlistUpdateInProgress), playlist_metadata_updated = Marshal.GetFunctionPointerForDelegate(_playlistMetadataUpdated), track_created_changed = Marshal.GetFunctionPointerForDelegate(_trackCreatedChanged), track_seen_changed = Marshal.GetFunctionPointerForDelegate(_trackSeenChanged), description_changed = Marshal.GetFunctionPointerForDelegate(_descriptionChanged), image_changed = Marshal.GetFunctionPointerForDelegate(_imageChanged), subscribers_changed = Marshal.GetFunctionPointerForDelegate(_subscribersChanged) }; lock (Spotify.Mutex) { Spotify.sp_playlist_add_callbacks(_playlist.Handle, ref _callbacks, IntPtr.Zero); } } }
public override void Initialize() { lock (Spotify.Mutex) { Spotify.sp_playlistcontainer_add_ref(Handle); } _callbacks = new NativePlaylistContainerCallbacks(this); _playlists = new Lazy <NativePlaylistList>(() => new NativePlaylistList( GetContainerLength, GetPlaylistAtIndex, AddNewPlaylist, AddExistingPlaylist, AddFolder, AddPlaylist, RemovePlaylist, RemovePlaylistAt, () => false, MovePlaylists)); }
public override void Initialize() { _browseComplete = new Spotify.AlbumBrowseCompleteCallback(OnBrowseCompleteCallback); _tracks = new DelegateArray <ITrack>(GetNumberOfTracks, GetTrackAtIndex); _copyrights = new DelegateArray <string>(GetNumberOfCopyrights, GetCopyrightAtIndex); if (_userData != null) { _userDataHandle = GCHandle.Alloc(_userData); } lock (Spotify.Mutex) { Handle = Spotify.sp_albumbrowse_create( Session.GetHandle(), _albumToBrowse.GetHandle(), _browseComplete, _userDataHandle.IsAllocated ? GCHandle.ToIntPtr(_userDataHandle) : IntPtr.Zero); } }