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

Android get URL of current track like iOS #35

Closed
tychota opened this issue Nov 9, 2016 · 5 comments
Closed

Android get URL of current track like iOS #35

tychota opened this issue Nov 9, 2016 · 5 comments

Comments

@tychota
Copy link

tychota commented Nov 9, 2016

Hey.

I'm instantiating a list of player on a react native page.
The goal is to display a list of question and let the user play the response of the question.

In peculiar if the user play a question, then click another question, it should stop the first and start the second.

When the user click on the question, onPress is called.

onAudioEvt = (evt: any) => {
    switch (evt.status) {
      case PLAYING:
        if (evt.url === this.getUrl()) {
          this.setState({ playing : true });
        } else {
          this.setState({ playing : false });
          this.subscription.remove();
          delete this.subscription;
        }
        break;
      case STOPPED:
      case ERROR:
        this.setState({ playing : false });
        this.subscription.remove();
        delete this.subscription;
        break;
    }
  }

  onPress = () => {
    if (!this.subscription) {
      this.subscription = DeviceEventEmitter.addListener('AudioBridgeEvent', this.onAudioEvt);
      ReactNativeAudioStreaming.play(this.getUrl(), {});
    } else {
      ReactNativeAudioStreaming.stop();
    }
  }

In ios this works fine because evt contain an url props (and also a duration that I ulse elsewhere but that is an other issue.

Is there a way on android to get the event current url ??

@tychota tychota changed the title Android get URL Android get URL of current track like iOS Nov 9, 2016
@tychota
Copy link
Author

tychota commented Nov 9, 2016

I'm not against contributing.

Will:

  • add the url as an intent parameter like broadcastedIntent.putExtra("url", "this.streamingURL");
  • sending the broadcast

works ?

@tlenclos
Copy link
Owner

Hi !

Yes we are missing some informations on the android side. We need url, duration and progress if possible on the events. Also on the method getStatus https://github.com/tlenclos/react-native-audio-streaming/blob/master/android/src/main/java/com/audioStreaming/ReactNativeAudioStreamingModule.java#L120.

Feel free to open a PR, thanks ;)

@tychota
Copy link
Author

tychota commented Nov 10, 2016

I managed to add url but I'm not abled to get duration and progress.
Do you know where I can get the info from accPlayer ?

So far my code in signal.java:

@Override
    public void playerPCMFeedBuffer(boolean isPlaying, int bufSizeMs, int bufCapacityMs) {
        if (isPlaying) {
            this.isPreparingStarted = false;
            if (bufSizeMs < 500) {
                this.isPlaying = false;
                sendBroadcast(new Intent(Mode.BUFFERING_START));
                //buffering
            } else {
                this.isPlaying = true;
                Intent BroadcastIntent = new Intent(Mode.PLAYING);
                BroadcastIntent.putExtra("url", this.streamingURL);
                BroadcastIntent.putExtra("duration", bufCapacityMs / 1000);
                BroadcastIntent.putExtra("progress", bufSizeMs / 1000);
                sendBroadcast(BroadcastIntent);
                //playing
            }
        } else {
            //buffering
            this.isPlaying = false;
            sendBroadcast(new Intent(Mode.BUFFERING_START));
        }
    }

and in eventReceiver.java:

@Override
    public void onReceive(Context context, Intent intent) {
        WritableMap params = Arguments.createMap();
        params.putString("status", intent.getAction());

        if (intent.getAction().equals(Mode.METADATA_UPDATED)) {
            params.putString("key", intent.getStringExtra("key"));
            params.putString("value", intent.getStringExtra("value"));
        }

        if (intent.getAction().equals(Mode.PLAYING)) {
            params.putString("url", intent.getStringExtra("url"));
            params.putString("duration", intent.getStringExtra("duration"));
            params.putString("progress", intent.getStringExtra("progress"));
        }

        this.module.sendEvent(this.module.getReactApplicationContextModule(), "AudioBridgeEvent", params);
    }

So far url works perfectly but I get null for both duration and progress.

I'm pretty sure I'm not that far but I guess I need a bit more help.

@tychota
Copy link
Author

tychota commented Nov 10, 2016

OKI. I was sending double and watching string.

I'm openning a PR.

tychota added a commit to bamlab/react-native-audio-streaming that referenced this issue Nov 10, 2016
@tychota
Copy link
Author

tychota commented Nov 18, 2016

The PR was rejected as the behaviour with progress was wrong. Basically it was not possible before we switch to a better android playing library.

This is handled in #12 .

So closing.

@tychota tychota closed this as completed Nov 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants