{"id":15371524,"url":"https://github.com/nathanwalker/nativescript-spotify","last_synced_at":"2025-04-15T14:12:47.067Z","repository":{"id":57308770,"uuid":"51404916","full_name":"NathanWalker/nativescript-spotify","owner":"NathanWalker","description":"A NativeScript plugin for the Spotify iOS and Android SDK's.","archived":false,"fork":false,"pushed_at":"2017-08-17T13:28:46.000Z","size":21093,"stargazers_count":25,"open_issues_count":5,"forks_count":12,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-15T14:12:30.642Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NathanWalker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-09T22:24:41.000Z","updated_at":"2023-07-12T10:53:05.000Z","dependencies_parsed_at":"2022-08-29T06:50:33.435Z","dependency_job_id":null,"html_url":"https://github.com/NathanWalker/nativescript-spotify","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NathanWalker%2Fnativescript-spotify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NathanWalker%2Fnativescript-spotify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NathanWalker%2Fnativescript-spotify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NathanWalker%2Fnativescript-spotify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NathanWalker","download_url":"https://codeload.github.com/NathanWalker/nativescript-spotify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249085427,"owners_count":21210267,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T13:47:23.955Z","updated_at":"2025-04-15T14:12:47.047Z","avatar_url":"https://github.com/NathanWalker.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"![alt text](resources/spotify.jpg \"Spotify\")\n\nA NativeScript plugin for the Spotify iOS and Android SDKs.\n\n* [Install](#install)\n* [Prerequisites](#prerequisites)\n* [Usage](#usage)\n* [Screenshots](#screenshots)\n* [Documentation](#documentation)\n* [Why the `TNS` prefixed name?](#why-the-tns-prefixed-name)\n* [Try it/Contributing](https://github.com/NathanWalker/nativescript-spotify/blob/master/docs/CONTRIBUTING.md)\n\n## Install\n\n```\nnpm install nativescript-spotify --save\n```\n\n## Prerequisites\n\n* Spotify streaming requires a **Premium** account.\n* Create a Spotify Developer account here: https://developer.spotify.com/\n* Create an app in your developer account and follow these instructions to get setup: https://developer.spotify.com/technologies/spotify-ios-sdk/tutorial/#creating-your-client-id-secret-and-callback-uri\n\n### Background\n\n* Based on the [Spotify iOS SDK Beta 13](https://github.com/spotify/ios-sdk/releases)\n* Android based on [Spotify Android SDK 1.0.0-beta13](https://github.com/spotify/android-sdk/releases)\n\n## Usage\n\n### Platform Prerequisites\n\n#### iOS\n\n### Setup\n\n* app.ts\n\nConfigure application launch phases to setup your Spotify App CLIENT_ID and REDIRECT_URL (the ones you created above in the developer account):\n\n```\nimport * as application from 'application';\nimport {NSSpotifyConstants, NSSpotifyAuth} from 'nativescript-spotify';\n\nclass MyDelegate extends UIResponder {\n  public static ObjCProtocols = [UIApplicationDelegate];\n  \n  public applicationDidFinishLaunchingWithOptions(application: UIApplication, launchOptions: NSDictionary): boolean {\n    \n    NSSpotifyConstants.CLIENT_ID = 'your spotify premium account api key';\n    TNSSpotifyAuth.REDIRECT_URL = 'your-app-custom-url-scheme://spotifylogin';\n    return true;\n  }\n}\napplication.ios.delegate = MyDelegate;\napplication.mainModule = \"main-page\";\napplication.cssFile = \"./app.css\";\napplication.start();\n```\n\n* main-page.ts\n\n```\nimport {SpotifyDemo} from \"./main-view-model\";\n\nfunction pageLoaded(args) {\n  var page = args.object;\n  page.bindingContext = new SpotifyDemo();\n}\nexports.pageLoaded = pageLoaded;\n```\n\n* main-view-model.ts\n\n```\nimport {Observable, EventData} from 'data/observable';\nimport {Page} from 'ui/page';\nimport {topmost} from 'ui/frame';\nimport {AnimationCurve} from 'ui/enums';\nimport * as loader from 'nativescript-loading-indicator';\nimport {TNSSpotifyConstants, TNSSpotifyAuth, TNSSpotifyPlayer, TNSSpotifyPlaylist, TNSSpotifyRequest, Utils} from 'nativescript-spotify';\n\nexport class SpotifyDemo extends Observable {\n  private _spotify: TNSSpotifyPlayer;\n\n  constructor() {\n    super();\n    \n    this._spotify = new TNSSpotifyPlayer();\n    \n    // when using iOS delegates that extend NSObject, TypeScript constructors are not used, therefore a separate `initPlayer()` exists\n    this._spotify.initPlayer(true); // passing `true` lets player know you want it to emit events (sometimes it's not desired)\n    \n    // small sample of events (see Documentation below for full list)\n    this._spotify.audioEvents.on('albumArtChange', (eventData) =\u003e {\n      this.updateAlbumArt(eventData.data.url);\n    });\n    this._spotify.audioEvents.on('authLoginSuccess', (eventData) =\u003e {\n      this.loginSuccess();\n    });\n  }\n  \n  public login() {\n    TNSSpotifyAuth.LOGIN();\n  }\n  \n  public play(args?: EventData) {\n    this._spotify.togglePlay('spotify:track:58s6EuEYJdlb0kO7awm3Vp').then((isPlaying: boolean) =\u003e {\n      console.log(isPlaying ? 'Playing!' : 'Paused!');\n    }, (error) =\u003e {\n      console.log(`Playback error: ${error}`);\n    });\n  }\n  \n  private updateAlbumArt(url: string) {\n    this.set(`currentAlbumUrl`, url);\n  }\n  \n  private loginSuccess() {\n    console.log(`loginSuccess!`);\n  } \n}\n```\n\n## Screenshots\n\nSample 1 |  Sample 2\n-------- | ---------\n![Sample1](screenshots/1.png) | ![Sample2](screenshots/2.png)\n\nSample 3 | Sample 4\n-------- | -------\n![Sample3](screenshots/3.png) | ![Sample4](screenshots/4.png)\n\n#### Android\n\n### Setup\n\n* Docs coming soon for Android...\n\n## Documentation\n\n### TNSSpotifyPlayer\n\nTNSSpotifyPlayer implements [SPTAudioStreamingPlaybackDelegate](https://developer.spotify.com/ios-sdk-docs/Documents/Protocols/SPTAudioStreamingPlaybackDelegate.html).\n\nCreating:\n```\n// Option 1: simple\nthis.spotify = new TNSSpotifyPlayer();\nthis.spotify.initPlayer();\n\n// Option 2: advanced\nthis.spotify = new TNSSpotifyPlayer();\n// passing `true` will let the player know it should emit events\nthis.spotify.initPlayer(true);\n\n// it allows you to listen to events like so:\nthis.spotify.audioEvents.on('startedPlayingTrack', (event) =\u003e {\n  console.log(event.data.url); // spotify track url\n});\n\n// play/pause a track\nthis.spotify.togglePlay('spotify:track:58s6EuEYJdlb0kO7awm3Vp').then((isPlaying: boolean) =\u003e {\n  console.log(isPlaying ? 'Playing!' : 'Paused!');\n}, (error) =\u003e {\n  console.log(`Playback error: ${error}`);\n});\n```\n\n#### Methods\n\nMethod |  Description\n-------- | ---------\n`togglePlay(track?: string)`: `Promise\u003cany\u003e` | Allows toggle play/pause on a track, or changing a track. `track` must be a valid spotify track uri. [Learn more here](https://developer.spotify.com/web-api/user-guide/#spotify-uris-and-ids) \n`isPlaying()`: `boolean` | Determine if player is currently playing\n`isLoggedIn()`: `boolean` | Determine if player is authenticated\n`setVolume(value: number)`: `Promise\u003cany\u003e` | Set the player volume\n`loadedTrack()`: `string` | Determine current loaded track (spotify track uri)\n`currentTrackMetadata()`: `ISpotifyTrackMetadata` | Get the current track's metadata. [Learn more here](https://developer.spotify.com/ios-sdk-docs/Documents/Classes/SPTAudioStreamingController.html#//api/name/currentTrackMetadata)\n\n#### Events\n\nEvent |  Description\n-------- | ---------\n`authLoginChange` | Sends along `data` = `status: boolean` When auth state changes.\n`authLoginCheck` | When auth callback has returned and is verifying authentication\n`authLoginSuccess` | When auth succeeded\n`albumArtChange` | Sends along `data` = `url: string` When track triggers a play start, this will also trigger to send along the correct album art of the track.\n`playerReady` | When the session has been validated and the player is ready to play.\n`changedPlaybackStatus` | Sends along `data` = `playing: boolean` When playback state changes.\n`seekedToOffset` | Sends along `data` = `offset: number` When player has seeked to a given offset.\n`changedVolume` | Sends along `data` = `volume: number` When the player volume was changed.\n`changedShuffleStatus` | Sends along `data` = `shuffle: number` When shuffle setting was changed.\n`changedRepeatStatus` | Sends along `data` = `repeat: number` When repeat setting was changed.\n`changedToTrack` | Sends along `data` = `metadata: any` When track change occurs.\n`failedToPlayTrack` | Sends along `data` = `url: string` When track play fails. Provides the url of the track that failed.\n`startedPlayingTrack` | Sends along `data` = `url: string` When track play starts. Provides the url of the track that started.\n`stoppedPlayingTrack` | Sends along `data` = `url: string` When track play stops. Provides the url of the track that stopped.\n`skippedToNextTrack` | When player skipped to next track.\n`skippedToPreviousTrack` | When player skipped to previous track.\n`activePlaybackDevice` | When the audio streaming object becomes the active playback device on the user’s account.\n`inactivePlaybackDevice` | When the audio streaming object becomes an inactive playback device on the user’s account.\n`poppedQueue` | When the audio streaming object becomes an inactive playback device on the user’s account.\n`temporaryConnectionError` | A temporary connection error occurred.\n`streamError` | Sends along `data` = `error: any` when a streaming error occurred.\n`receivedMessage` | Sends along `data` = `message: string` when a message is received from the Spotify service.\n`streamDisconnected` | When the stream becomes disconnected.\n\n### TNSSpotifyAuth\n\nTNSSpotifyAuth\n\nProvides `static` properties and methods to help with authentication handling and user management.\n\n#### Properties\n\nProperty |  Description\n-------- | ---------\n`REDIRECT_URL`: `string` | Used to set your spotify application redirect url, required for device auth redirect, ie: `'your-app-custom-url-scheme://spotifylogin'`\n`SESSION`: `SPTSession` | Represents the current auth session.\n`CLEAR_COOKIES`: `boolean` | Clear cookies in auth window to not remember last logged in user. Defaults `false`.\n`PREMIUM_MSG`: `string` | The message which alerts when a non-premium user attempts to play a track.\n\n#### Methods\n\nMethod |  Description\n-------- | ---------\n`LOGIN()`: `void` | Initiates login sequence.\n`LOGIN_WITH_SESSION(session)`: `void` | Logs user in with session returned from the in-app browser auth window.\n`LOGOUT()`: `void` | Clear's persisted user session and notifies of login change.\n`HANDLE_AUTH_CALLBACK(url)`: `boolean` | When using standard browser redirect auth, this can be used in application launch phase to handle the auth redirect back into the app. On older versions, this may be needed.\n`VERIFY_SESSION(session?: any)`: `Promise\u003cany\u003e` | Mainly used internally, but used to restore a session from local persistence and/or renew.\n`SAVE_SESSION(session)`: `void` | Mainly used internally, but can be used to persist a valid Spotify session.\n`GET_STORED_SESSION()`: `any` | Get the current user's session. [Learn more here](https://developer.spotify.com/ios-sdk-docs/Documents/Classes/SPTSession.html)\n`RENEW_SESSION(session)`: `Promise\u003cany\u003e` | Can be used to pass an expired session to renew it.\n`CURRENT_USER()`: `Promise\u003cany\u003e` | Get the current user object. [Learn more here](https://developer.spotify.com/ios-sdk-docs/Documents/Classes/SPTUser.html)\n\n### TNSSpotifySearch\n\nTNSSpotifyAuth\n\nProvides 1 `static` method to search Spotify.\n\n#### Methods\n\nMethod |  Description\n-------- | ---------\n`QUERY(query: string, queryType: string, offset: number = 0)`: `Promise\u003cany\u003e` | Search and paginate through query results of Spotify search results. Resolves an Object structure: `{page: number (offset), hasNextPage: boolean, totalListLength: number, tracks: Array}`. Right now using `queryType` = `'track'` is supported. More query types coming soon.\n\n## Why the TNS prefixed name?\n\n`TNS` stands for **T**elerik **N**ative**S**cript\n\niOS uses classes prefixed with `NS` (stemming from the [NeXTSTEP](https://en.wikipedia.org/wiki/NeXTSTEP) days of old):\nhttps://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/\n\nTo avoid confusion with iOS native classes, `TNS` is used instead.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathanwalker%2Fnativescript-spotify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnathanwalker%2Fnativescript-spotify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathanwalker%2Fnativescript-spotify/lists"}