Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES6 integration (?) #85

Open
DalerAsrorov opened this issue Sep 1, 2017 · 1 comment
Open

ES6 integration (?) #85

DalerAsrorov opened this issue Sep 1, 2017 · 1 comment

Comments

@DalerAsrorov
Copy link

DalerAsrorov commented Sep 1, 2017

Hello, thanks a lot for building the API.

Is there any plans to have an ES6 wrapper of the API? So we could do something like:

import SC from 'soundcloud'; 

SC.init({ ... }); 
SC.get('/tracks', { genres: 'rock' }); 
@ProLoser
Copy link

ProLoser commented Aug 1, 2018

I don't know why this wouldn't work but it doesn't.

sdk.js:23 Uncaught TypeError: Cannot read property 'AudioContext' of undefined

import SC from 'soundcloud';
import EVENTS from '../Events';

let track = `/tracks/${window.location.search.substr(1)}`;

const SOUNDCLOUD_STATES = {
  'playing': EVENTS.PLAYING,
  'paused': EVENTS.PAUSED,
  'loading': EVENTS.LOADING,
  'ended': EVENTS.COMPLETE,
  'error': EVENTS.ERROR
};

SC.stream(track).then(function(player){
  player.play();


  player.on('state-change', event => {
    window.postMessageNative(SOUNDCLOUD_STATES[event], '*');
  });


  document.addEventListener('message', window.listener = function(event) {
    let data = JSON.parse(event.data);
    switch (data.type) {
      case EVENTS.PLAY:
        player.play();
        break;
      case EVENTS.PAUSE:
        player.pause();
        break;
      case EVENTS.VOLUME:
        player.setVolume(.5);
        break;
    }
  });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants