Skip to content

Commit

Permalink
Merge pull request #43 from cjam/feat/android-support
Browse files Browse the repository at this point in the history
Feat/android support
  • Loading branch information
cjam authored May 17, 2020
2 parents 39899b9 + 8c76d44 commit d1a1f5f
Show file tree
Hide file tree
Showing 92 changed files with 9,090 additions and 3,234 deletions.
42 changes: 42 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"projectName": "react-native-spotify-remote",
"projectOwner": "cjam",
"repoType": "github",
"repoHost": "https://github.com",
"files": [
"README.md"
],
"imageSize": 100,
"commit": false,
"commitConvention": "none",
"contributors": [
{
"login": "cjam",
"name": "Colter McQuay",
"avatar_url": "https://avatars2.githubusercontent.com/u/1000288?v=4",
"profile": "https://github.com/cjam",
"contributions": [
"code"
]
},
{
"login": "lufinkey",
"name": "Luis Finke",
"avatar_url": "https://avatars3.githubusercontent.com/u/7820113?v=4",
"profile": "https://github.com/lufinkey",
"contributions": [
"ideas"
]
},
{
"login": "YozhikM",
"name": "Stanislav",
"avatar_url": "https://avatars0.githubusercontent.com/u/27273025?v=4",
"profile": "https://github.com/YozhikM",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7
}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ project.xcworkspace

# Android/IntelliJ
#
android/.project
android/.settings
/android/gradle/
gradlew
gradlew.bat
Expand All @@ -46,6 +48,9 @@ build/
.gradle
local.properties
*.iml
example/android/.project
example/android/.settings
*.aab

# BUCK
buck-out/
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
path = ios/external/SpotifySDK
url = https://github.com/spotify/ios-sdk.git
ignore = dirty
[submodule "android/external/SpotifySDK"]
path = android/external/SpotifySDK
url = https://github.com/spotify/android-sdk.git
ignore = dirty
13 changes: 11 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@
/ios/external/SpotifySDK/docs
/ios/external/SpotifySDK/DemoProjects
/ios/external/SpotifySDK/img
/android/gradle/
/android/.gradle/
/android/build/
/android/external/SpotifySDK/app-remote-sample
/android/external/SpotifySDK/auth-sample
/android/external/SpotifySDK/app-remote-lib/docs
/android/external/SpotifySDK/app-remote-lib/img
/android/external/SpotifySDK/auth-lib/docs
/android/external/SpotifySDK/*.*
/src/
gradlew
gradlew.bat
build/
gradlew
gradlew.bat
.idea
.gradle
local.properties
*.iml
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Changed
- `ApiConfig.scope` to `ApiConfig.scopes` which is now of type `ApiScope[]` and also aligns to the web api scopes
- `ApiScope` enum values are now same as web api instead of bit flags
- `PlayerState.paused` -> `PlayerState.isPaused` to align with Spotify's iOS/Android sdk's

### Added
- Android Support! Big thanks to @YozhikM for the initial work on this
- `PlaybackRestrictions.canSeek`
- `SpotifyRemote.getChildrenOfItem` now has optional `options:GetChildrenItemsOptions` for android paging
- `SpotifyAuth.authorize` to replace `SpotifyAuth.initialize` which will now return a session object instead of just a token

### Deprecated
- `SpotifyAuth.initialize` in favor of `SpotifyAuth.authorize`

### Removed


## [0.2.2] - 2020-03-22
### Changed
Expand Down
169 changes: 80 additions & 89 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,54 @@

# Spotify App Remote for React Native

A react native module for the Spotify Remote SDK.
[![npm version](https://badge.fury.io/js/react-native-spotify-remote.svg)](https://badge.fury.io/js/react-native-spotify-remote)

>## ⚠️ Work In Progress ⚠️
>## Currently Only Implemented for iOS
A react native module for the Spotify Remote SDK ( [iOS](https://github.com/spotify/ios-sdk/) | [Android](https://github.com/spotify/android-sdk/) )

- [Documentation](https://cjam.github.io/react-native-spotify-remote/index.html)
- [Change Log](./CHANGELOG.md)
- [Contributing](./CONTRIBUTING.md)

## Supported Features

An [Example](./example) project was developed to exercise and test all functionality within this library. If you are curious about how to use something, or need to compare your application setup to something that works, check there first.

## Features

The following table shows the platform support for various Spotify Remote API functionality within this library.

|Feature|iOS|Android||
|:--|:-:|:-:|-:|
|Authentication|
|`authorize` ||||
|`getSession` ||||
|`endSession` ||||
|Remote|
|`isConnectedAsync` ||||
|`connect` ||||
|`disconnect` ||||
|`playUri` ||||
|`playItem` ||||
|`playItemWithIndex` ||||
|`queueUri` ||||
|`seek` ||||
|`resume` ||||
|`pause` ||||
|`skipToNext` ||||
|`skipToPrevious` ||||
|`setShuffling` ||||
|`setRepeatMode` ||||
|`getPlayerState` ||||
|`getRootContentItems` |||Not available in Android SDK|
|`getRecommendedContentItems` ||||
|`getChildrenOfItem` ||||
|`getContentItemForUri` |||Not available in Android SDK|
|`getCrossfadeState` ||||
|Remote Events|
|`playerStateChanged` ||||
|`remoteDisconnected` ||||
|`remoteConnected` ||||

## Install

```bash
Expand All @@ -25,6 +63,8 @@ npm install --save react-native-spotify-remote

## Linking

As of React Native `> 0.61`, auto linking should work for both iOS and Android. There shouldn't be any modifications necessary and it *Should* work out of the box. The one caveat, is that `react-native-events` needs to be linked as it doesn't yet support auto linking. If you do run into issues or are using an older version of React Native, the following sections should help get you up and running.

### iOS

>This library requires being built with **XCode 11** for reasons given [here](https://github.com/spotify/ios-sdk/issues/179#issuecomment-581032275).
Expand Down Expand Up @@ -85,102 +125,34 @@ Modifications are needed for the `AppDelegate.m`:
@end
```
<!--
#### Android
### Android
If you need to link your project manually, here are some things you'll need to do.
1. Open up `android/app/src/main/java/[...]/MainActivity.java`
1. Open up `android/app/src/main/java/[...]/MainApplication.java`
- Add `import com.reactlibrary.RNSpotifyRemotePackage;` to the imports at the top of the file
- Add `new RNSpotifyRemotePackage()` to the list returned by the `getPackages()` method
2. Append the following lines to `android/settings.gradle`:
```
include ':react-native-spotify-remote'
project(':react-native-spotify-remote').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-spotify-remote/android')
include ':react-native-spotify-remote'
project(':react-native-spotify-remote').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-spotify-remote/android')
include ':react-native-events'
project(':react-native-events').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-events/android')
```
3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
```
compile project(':react-native-spotify-remote')
implementation project(':react-native-spotify-remote')
implementation project(':react-native-events')
```
Edit `android/build.gradle` and add `flatDir`
```
...
allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
flatDir {
dirs project(':react-native-spotify-remote').file('libs'), 'libs'
}
}
}
...
```
Edit `android/app/build.gradle` and add `packagingOptions`
```
...
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
packagingOptions {
pickFirst 'lib/armeabi-v7a/libgnustl_shared.so'
pickFirst 'lib/x86/libgnustl_shared.so'
}
...
```
If you have issues linking the module, please check that gradle is updated to the latest version and that your project is synced. -->
## Features
The following table is here to show the support for Spotify Remote API functionality within this library.
|Feature|iOS|Android|
|:--|:-:|:-:|
|Authentication|
|`initialize`|[x]|[ ]|
|`getSession`|[x]|[ ]|
|`endSession`|[x]|[ ]|
|Remote|
|`isConnectedAsync`|[x]|[ ]|
|`connect`|[x]|[ ]|
|`playUri`|[x]|[ ]|
|`playItem`|[x]|[ ]|
|`playItemWithIndex`|[x]|[ ]|
|`queueUri`|[x]|[ ]|
|`seek`|[x]|[ ]|
|`resume`|[x]|[ ]|
|`pause`|[x]|[ ]|
|`skipToNext`|[x]|[ ]|
|`skipToPrevious`|[x]|[ ]|
|`setShuffling`|[x]|[ ]|
|`setRepeatMode`|[x]|[ ]|
|`getPlayerState`|[x]|[ ]|
|`getRootContentItems`|[x]|[ ]|
|`getRecommendedContentItems`|[x]|[ ]|
|`getChildrenOfItem`|[x]|[ ]|
|`getContentItemForUri`|[x]|[ ]|
|`getCrossfadeState`|[x]|[ ]|
|Remote Events|
|`playerStateChanged`|[x]|[ ]|
|`remoteDisconnected`|[x]|[ ]|
|`remoteConnected`|[x]|[ ]|
## Usage
### Example Application
This repo contains an [Example App](./example/Readme.md) which should be the quickest and easiest way to get up and running to try things out. It is using React Hooks (cuz they're pretty cool) and is using a few of the remote API calls. (Will be looking to show use of all of the api calls in the near future).
This repo contains an [Example App](./example/Readme.md) which should be the quickest and easiest way to get up and running to try things out. It is using React Hooks (cuz they're pretty cool) and exercises all of the remote API calls.
### In Code
Expand All @@ -202,15 +174,15 @@ const spotifyConfig: ApiConfig = {
redirectURL: "SPOTIFY_REDIRECT_URL",
tokenRefreshURL: "SPOTIFY_TOKEN_REFRESH_URL",
tokenSwapURL: "SPOTIFY_TOKEN_SWAP_URL",
scope: ApiScope.AppRemoteControlScope | ApiScope.UserFollowReadScope
scopes: [ApiScope.AppRemoteControlScope, ApiScope.UserFollowReadScope]
}
// Initialize the library and connect the Remote
// then play an epic song
async function playEpicSong(){
try{
const token = await SpotifyAuth.initialize(spotifyConfig);
await SpotifyRemote.connect(token);
const session = await SpotifyAuth.authorize(spotifyConfig);
await SpotifyRemote.connect(session.token);
await remote.playUri("spotify:track:6IA8E2Q5ttcpbuahIejO74");
await remote.seek(58000);
}catch(err){
Expand All @@ -235,6 +207,25 @@ Nothing has been special to deal with Spotify *Free* Users but this module _shou

Please do not open issues about getting the module to work unless you have tried using both the example app and the example token swap server. Please make sure you have tried running on the latest react-native version before submitting a bug.

## Acknowledgements
## Contributors

Big thanks to [@lufinkey](https://github.com/lufinkey) and all of the great work that he has done in the [react-native-spotify](https://github.com/lufinkey/react-native-spotify) repo which was the original source of inspiration and some useful patterns for this package.

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="https://github.com/cjam"><img src="https://avatars2.githubusercontent.com/u/1000288?v=4" width="100px;" alt=""/><br /><sub><b>Colter McQuay</b></sub></a><br /><a href="https://github.com/cjam/react-native-spotify-remote/commits?author=cjam" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/lufinkey"><img src="https://avatars3.githubusercontent.com/u/7820113?v=4" width="100px;" alt=""/><br /><sub><b>Luis Finke</b></sub></a><br /><a href="#ideas-lufinkey" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="https://github.com/YozhikM"><img src="https://avatars0.githubusercontent.com/u/27273025?v=4" width="100px;" alt=""/><br /><sub><b>Stanislav</b></sub></a><br /><a href="https://github.com/cjam/react-native-spotify-remote/commits?author=YozhikM" title="Code">💻</a></td>
</tr>
</table>

Big thanks to [@lufinkey](https://github.com/lufinkey) and all of the great work that he has done in the [react-native-spotify](https://github.com/lufinkey/react-native-spotify) repo which was the original source of inspiration & coding patterns for this package.
<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
Loading

0 comments on commit d1a1f5f

Please sign in to comment.