This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class AppleMusicPlayBehavior implements IPlayBehaviour { | |
public TAG: string; | |
public playState: PlayStateEnum; | |
public playedMs: number; | |
public playlist: NowPlayingPlaylistModel = new NowPlayingPlaylistModel(); | |
public progress: number; | |
public trackPlayedLabel: string; | |
public trackRemainingLabel: string; | |
public volume: number; | |
musicKit: MusicKitInstance; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import MusicKitInstance = MusicKit.MusicKitInstance; | |
import AppleMusicKit = MusicKit; | |
export class AppleMusicEngine extends EngineBase implements IStreamEngine { | |
TAG = 'AppleMusicEngine'; | |
musicKit: MusicKitInstance; | |
constructor( | |
instanciatedByTAG: string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener('musickitconfigured', function () { | |
console.log('musickitconfigured event triggered'); | |
}) | |
document.addEventListener('musickitloaded', function () { | |
// MusicKit global is now defined | |
MusicKit.configure({ | |
developerToken: 'YOUR DEVELOPER TOKEN HERE', | |
app: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
const fs = require("fs"); | |
const jwt = require("jsonwebtoken"); | |
const request = require("request"); | |
const privateKey = fs.readFileSync("AuthKey.p8").toString(); //your MusicKit private key | |
const jwtToken = jwt.sign({}, privateKey, { | |
algorithm: "ES256", | |
expiresIn: "180d", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private async _transferDevice(): Promise<void> { | |
const devicesResponse = await this.dataService.put<void>( | |
'https://api.spotify.com/v1/me/player', | |
JSON.stringify({device_ids: [this.deviceService.activeDevice.id]}), | |
{ | |
headers: { | |
'Content-Type': 'application/json', | |
Authorization: `Bearer ${this.authorizationService.spotifyAccessToken}` | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private async _setVolume(volume: number): Promise<void> { | |
const devicesResponse = await this.dataService.put<void>( | |
'https://api.spotify.com/v1/me/player/volume?volume_percent=' + volume + '&device_id=' + this.deviceService.activeDevice.id, | |
null, | |
{ | |
headers: { | |
'Content-Type': 'application/json', | |
Authorization: `Bearer ${this.authorizationService.spotifyAccessToken}` | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private async _seek(positionMs: number): Promise<void> { | |
await this.dataService.put<any>( | |
`https://api.spotify.com/v1/me/player/seek?position_ms=${positionMs}`, | |
null, | |
{ | |
headers: { | |
'Content-Type': 'application/json', | |
Authorization: `Bearer ${this.authorizationService.spotifyAccessToken}` | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class SpotifyEngine extends EngineBase | |
implements IStreamEngine{ | |
///... | |
private async playTrack(trackId: string): Promise<void> { | |
await this.dataService.put<any>( | |
SpotifyURLResources.PlayTrack + `?device_id=${this.deviceService.activeDevice.id}`, | |
JSON.stringify({uris: [trackId]}), | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class SpotifyEngine extends EngineBase | |
implements IStreamEngine{ | |
///... | |
private async getAlbums(): Promise<Array<AlbumModel>> { | |
const limitQueryString = '?limit=50'; | |
const result = new Array<AlbumModel>(); | |
let url = SpotifyURLResources.UsersSavedAlbums + limitQueryString; | |
do { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); // Express web server framework | |
var request = require('request'); // "Request" library | |
var cors = require('cors'); | |
var querystring = require('querystring'); | |
var cookieParser = require('cookie-parser'); | |
var client_id = '*****'; // Your client id | |
var client_secret = '****'; // Your secret | |
var redirect_uri = 'http://localhost:8888/callback'; // Your redirect uri |