SpotifySDK﹕ Got error 8 using SpotifySdkAndroid-1.0.0-beta3 - android

Getting below error while playing
sample song spotify:track:2TpxZ7JUBn3uw46aR7qd6V
I/SpotifySDK﹕ Got notification: Became active playing device
I/SpotifySdkDemo﹕ Player event: became active
**E/SpotifySDK﹕ Got error 8**
Sample Code
Spotify spotify = new Spotify(access_token);
mPlayer = spotify.getPlayer(this, "My Company Name", this,
new Player.InitializationObserver() {
#Override
public void onInitialized() {
mPlayer.addConnectionStateCallback(SpotifyAuthActivityDemo.this);
mPlayer.addPlayerNotificationCallback(SpotifyAuthActivityDemo.this);
mPlayer.play("spotify:track:2TpxZ7JUBn3uw46aR7qd6V");
}
#Override
public void onError(Throwable throwable) {
Log.e("MainActivity", "Could not initialize player: " + throwable.getMessage());
}
});

Error 8 is "Login failed: Bad credentials". Check your login credentials and handle the appropriate login events in the SDK accordingly.

Related

ConnectSDK Android

Working with connectSDK Android for casting videos on samsung android Tv.
I've successfully launch the default youtube app and played as well.
But when ever i'm trying to stop the currently running Youtube video getting a response code = 400 i.e
com.connectsdk.service.command.ServiceCommandError: Bad Request
Anyone worked on this? or familiar with the issue?
Code:
if (runningAppSession != null) {
if (runningAppSession.getSessionType() == LaunchSessionType.App) {
getLauncher().closeApp(runningAppSession, new ResponseListener<Object>() {
#Override
public void onError(ServiceCommandError error) {
System.out.println(error);
}
#Override
public void onSuccess(Object object) {
System.out.println(object.toString());
}
});
}
}

Cast to youtube chromecast receiver from other android app

I'm adding chromecast support to the app Narwhal TV for reddit https://play.google.com/store/apps/details?id=org.elsewhat.reddit&hl=en
As it aggregates youtube videos popular on reddit, I want to reuse the youtube chromecast receiver app.
I've made some progress already: I'm able to connect to the chromecast device and start the youtube app.
However, I am not able to start the playback of a video. Most of this progress is due to the castv2-youtube project https://github.com/xat/castv2-youtube
Start the youtube application
private String CHROMECAST_APP_ID="233637DE";
Cast.CastApi.launchApplication(mApiClient, CHROMECAST_APP_ID, false)
Define the youtube channel
class YoutubeChannel implements Cast.MessageReceivedCallback {
public String getNamespace() {
return "urn:x-cast:com.google.youtube.mdx";
}
#Override
public void onMessageReceived(CastDevice castDevice, String namespace,
String message) {
Log.d("RedditTV", "onMessageReceived: " + message);
}
}
Listen to both the media and youtube channels
Cast.CastApi.setMessageReceivedCallbacks(mApiClient,
mRemoteMediaPlayer.getNamespace(), mRemoteMediaPlayer);
Cast.CastApi.setMessageReceivedCallbacks(mApiClient,
youtubeChannel.getNamespace(),
youtubeChannel);
Send message to start the video
String message = String.format(locale,"{\"type\":\"flingVideo\", \"data\":{\"videoId\":\""+redditPost.getYoutubeId()+"\" ,\"currentTime\":%.2f}}",time) ;
Log.w("RedditTV", "Chromecast message to "+ youtubeChannel.getNamespace() + " :"+message);
try {
Cast.CastApi.sendMessage(mApiClient, youtubeChannel.getNamespace(), message)
.setResultCallback(
new ResultCallback<Status>() {
#Override
public void onResult(Status result) {
if (!result.isSuccess()) {
Log.e("RedditTV", "Sending message failed");
}
}
});
} catch (Exception e) {
Log.e("RedditTV", "Exception while sending message", e);
}
The output of shows the actual message sent (I've also tried to set currentTime as 0)
Chromecast message to urn:x-cast:com.google.youtube.mdx :{"type":"flingVideo", "data":{"videoId":"4Bn2SEHsyNY" ,"currentTime":1420065958051.00}}
The message is sent successfully, but nothing happens on the chromecast side.
I don't have any good way of debugging it either.

Chromecast Android Sender RemoteMediaPlayer producing No current media session

I have been able to successfully cast video to a Chromecast and have the option let the video play when disconnecting and it all works great. However, if I choose to quit the application and let the video continue playing and then try to re-join the currently playing session and try to use the RemoteMediaPlayer to control the video I am getting: "java.lang.IllegalStateException: No current media session".
Just as a background, I am saving the route id and session id on the initial connect into preferences and am able to successfully call "Cast.CastApi.joinApplication" and when in the onResult I am recreating the Media Channel and setting the setMessageReceivedCallbacks like so:
Cast.CastApi.joinApplication(mApiClient,"xxxxxxxx",persistedSessionId).setResultCallback(new ResultCallback<Cast.ApplicationConnectionResult>() {
#Override
public void onResult(Cast.ApplicationConnectionResult applicationConnectionResult) {
Status status = applicationConnectionResult.getStatus();
if (status.isSuccess()) {
mRemoteMediaPlayer = new RemoteMediaPlayer();
mRemoteMediaPlayer.setOnStatusUpdatedListener(
new RemoteMediaPlayer.OnStatusUpdatedListener() {
#Override
public void onStatusUpdated() {
Log.d("----Chromecast----", "in onStatusUpdated");
}
});
mRemoteMediaPlayer.setOnMetadataUpdatedListener(
new RemoteMediaPlayer.OnMetadataUpdatedListener() {
#Override
public void onMetadataUpdated() {
Log.d("----Chromecast----", "in onMetadataUpdated");
}
});
try {
Cast.CastApi.setMessageReceivedCallbacks(mApiClient,mRemoteMediaPlayer.getNamespace(), mRemoteMediaPlayer);
} catch (IOException e) {
Log.e("----Chromecast----", "Exception while creating media channel", e);
}
//-----------RESOLUTION START EDIT------------------
mRemoteMediaPlayer.requestStatus(mApiClient).setResultCallback(new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {
#Override
public void onResult(RemoteMediaPlayer.MediaChannelResult mediaChannelResult) {
Status stat = mediaChannelResult.getStatus();
if(stat.isSuccess()){
Log.d("----Chromecast----", "mMediaPlayer getMediaStatus success");
// Enable controls
}else{
Log.d("----Chromecast----", "mMediaPlayer getMediaStatus failure");
// Disable controls and handle failure
}
}
});
//-----------RESOLUTION END EDIT------------------
}else{
Log.d("----Chromecast----", "in status failed");
}
}
}
If I declare the RemoteMediaPlayer as static:
private static RemoteMediaPlayer mRemoteMediaPlayer;
I can join the existing session as well as control the media using commands like:
mRemoteMediaPlayer.play(mApiClient);
or
mRemoteMediaPlayer.pause(mApiClient);
But once I quit the application obviously the static object is destroyed and the app produces the aforementioned "No current media session" exception. I am definitely missing something because after I join the session and register the callback perhaps I need to start the session just like it was creating when I initially loaded the media using mRemoteMediaPlayer.load(.
Can someone please help as this is very frustrating?
The media session ID is part of the internal state of the RemoteMediaPlayer object. Whenever the receiver state changes, it sends updated state information to the sender, which then causes the internal state of the RemoteMediaPlayer object to get updated.
If you disconnect from the application, then this state inside the RemoteMediaPlayer will be cleared.
When you re-establish the connection to the (still running) receiver application, you need to call RemoteMediaPlayer.requestStatus() and wait for the OnStatusUpdatedListener.onStatusUpdated() callback. This will fetch the current media status (including the current session ID) from the receiver and update the internal state of the RemoteMediaPlayer object accordingly. Once this is done, if RemoteMediaPlayer.getMediaStatus() returns non-null, then it means that there is an active media session that you can control.
As user3408864 pointed out, requestStatus() after rejoining the session works. Here is how i managed to solve it in my case and it should work in yours.
if(MAIN_ACTIVITY.isConnected()){
if(MAIN_ACTIVITY.mRemoteMediaPlayer == null){
MAIN_ACTIVITY.setRemoteMediaPlayer();
}
MAIN_ACTIVITY.mRemoteMediaPlayer.requestStatus(MAIN_ACTIVITY.mApiClient).setResultCallback( new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {
#Override
public void onResult(RemoteMediaPlayer.MediaChannelResult mediaChannelResult) {
if(playToggle ==0){
try {
MAIN_ACTIVITY.mRemoteMediaPlayer.pause(MAIN_ACTIVITY.mApiClient);
playToggle =1;
} catch (IOException e) {
e.printStackTrace();
}
}else{
try {
MAIN_ACTIVITY.mRemoteMediaPlayer.play(MAIN_ACTIVITY.mApiClient);
playToggle =0;
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
}
Ignore, MAIN_ACTIVITY, it is just a static reference to my activity since i run this piece of code from a Service. Also, setRemoteMediaPlayer() is a method where i create a new RemoteMediaPlayer() and attach the corresponding Listeners.
Hopefully this helps. Also, sorry if any mistake, it is my first post to StackOverFlow.

chromecast "failed to start application: no application is running" after called startSession()

I'm testing playing online video using chromecast.
After onRouteSelected(), I create the ApplicationSession and attach a MediaProtocalMessageStream;
Then I called mSession.startSession(); with no APP_ID, so I assume the build-in app inside chromecast play the video for me. This code works perfect and I can play online mp4 videos without writing my own receiver.
But, When I try to leave the video play app, I can't go back anymore, there is always an error message comes from onSessionStartFailed() which says
StartSessionTask failed with error: failed to start application: no
application is running
I don't remember how the first time I got into the video play app, which I don't leave for few day.
But I do know how I leave it, Here is what I did before I can never startSession again:
open Youtube app, get a deviced connected
play some youtube videos
disconnected from a chormecast, then the chromecast return to the starting page
So, doesn't anybody know what's going on here? How to open the build-in video app again?
By the way, My chromecast get a system update just after I return to the starting page, I don't know if google update something cause startSession() fail.
Below is the code I startSession and attach a mediaStream.
mSession = new ApplicationSession(mCastContext, mSelectedDevice);
ApplicationSession.Listener listener = new ApplicationSession.Listener() {
#Override
public void onSessionStarted(ApplicationMetadata appMetadata) {
mChannel = mSession.getChannel();
mStream = new MediaProtocolMessageStream();
mChannel.attachMessageStream(mStream);
if (mStream.getPlayerState() == null) {
ContentMetadata metaData = new ContentMetadata();
metaData.setTitle("Test Video");
String url = "http://www.auby.no/files/video_tests/h264_720p_hp_5.1_6mbps_ac3_planet.mp4";
try {
mCommand = mStream.loadMedia(url, metaData, true);
mCommand.setListener(new MediaProtocolCommand.Listener() {
#Override
public void onCompleted(MediaProtocolCommand arg0) {
onSetVolume(0.5);
}
#Override
public void onCancelled(MediaProtocolCommand arg0) {
}
});
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
#Override
public void onSessionStartFailed(SessionError error) {
Log.d("TEST", "Session Started failed");
}
#Override
public void onSessionEnded(SessionError error) {
Log.d("TEST", "Session Started end");
}
};
mSession.setListener(listener);
try {
mSession.startSession();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
You will have to use your own app id and own receiver. Google's default receiver doesn't play video streams anymore (it used to). It only handles Chrome tab mirroring now.

android market not updating on phone

I am trying to test in-app billing in my Android application. The problem is, it appears my market is not up to date since I can't bind to the billing service(I am using the Android example code from here. I keep getting the message This app cannot connect to Market.
Your version of Market may be out of date.
You can continue to use this app but you
won\'t be able to make purchases.
I tried updating the market by opening it, hitting the home, and waiting 5-10 minutes and trying again as outlined here, but it didn't fix the problem. I am testing on a Nexus One with no phone connection - just over WiFi(not sure if this is relevant) with OS 2.2. Has anyone else run into this problem?
Here is the code from my activity:
if (!mBillingService.checkBillingSupported()) {
showDialog(DIALOG_CANNOT_CONNECT_ID);
}
and this is the code from my billing service that is showing the billing is not supported:
public boolean checkBillingSupported() {
return new CheckBillingSupported().runRequest();
}
class CheckBillingSupported extends BillingRequest {
public CheckBillingSupported() {
// This object is never created as a side effect of starting this
// service so we pass -1 as the startId to indicate that we should
// not stop this service after executing this request.
super(-1);
}
#Override
protected long run() throws RemoteException {
Bundle request = makeRequestBundle("CHECK_BILLING_SUPPORTED");
Bundle response = mService.sendBillingRequest(request);
int responseCode = response.getInt(Consts.BILLING_RESPONSE_RESPONSE_CODE);
if (Consts.DEBUG) {
Log.i(TAG, "CheckBillingSupported response code: " +
ResponseCode.valueOf(responseCode));
}
boolean billingSupported = (responseCode == ResponseCode.RESULT_OK.ordinal());
ResponseHandler.checkBillingSupportedResponse(billingSupported);
return Consts.BILLING_RESPONSE_INVALID_REQUEST_ID;
}
}
private boolean bindToMarketBillingService() {
try {
if (Consts.DEBUG) {
Log.i(TAG, "binding to Market billing service");
}
boolean bindResult = bindService(
new Intent(Consts.MARKET_BILLING_SERVICE_ACTION),
this, // ServiceConnection.
Context.BIND_AUTO_CREATE);
if (bindResult) {
return true;
} else {
Log.e(TAG, "Could not bind to service.");
}
} catch (SecurityException e) {
Log.e(TAG, "Security exception: " + e);
}
return false;
}
Maybe it requires the phone to have a mobile data connection. You can try to install the latest market app manually.

Categories

Resources