Cast to youtube chromecast receiver from other android app - android

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.

Related

quickblox OnMessageListener is not receiveing qbprivate message with attachment

i have implemented quickblox successfully earlier for my android chat apps for only text chat. this time i want to send message with image as attachment. File is sending successfully ( i have checked it in quickblox admin Content panel). But in the receiver part it is not displaying image or text. I am getting nor any Exception/ error or text in logcat. So it's very difficult to trace out the wrong code, i m doing. plz help.
MyChatControlle
------------------------`private QBPrivateChatManagerListener chatManagerListener=new QBPrivateChatManagerListener() {
#Override
public void chatCreated(QBPrivateChat qbPrivateChat, boolean b) {
if(!b) {
qbPrivateChat.addMessageListener(myListener);
}
}
};`
private QBMessageListener myListener=new QBMessageListener() {
#Override
public void processMessage(QBChat qbChat, QBChatMessage qbChatMessage) {
int frm=qbChatMessage.getSenderId();
int tos=qbChatMessage.getRecipientId();
System.out.println(String.format(">>> Message received (from=%s, to=%s): %s", frm, tos, qbChatMessage.getBody()));
if (onMessageReceivedListener != null) {
onMessageReceivedListener.onMessageReceived(qbChatMessage);
}
}
#Override
public void processError(QBChat qbChat, QBChatException e, QBChatMessage qbChatMessage) { }
};
ChatActivity
MyChatController.OnMessageReceivedListener onMessageReceivedListener = new MyChatController.OnMessageReceivedListener() {
#Override
public void onMessageReceived(final QBChatMessage msg) {
try {
final String mmsg = msg.getBody();
Toast.makeText(getApplicationContext(), "Receiving..."+mmsg, Toast.LENGTH_LONG).show();
}catch (Exception e){
Toast.makeText(getApplicationContext(),"#A#B#"+e.toString(), Toast.LENGTH_LONG).show();
}
}
};
You can use latest version of QuickBlox Android SDK without chat managers. In newest versions you can use QBChatDialog model to perform all chat functions. Additionally check all parameters of your attachment, they mast be not null and not empty. Can you provide message, which didn't catch by listener (.xml from logcat)?

Android Google Play Games Services Turn based Multiplayer not Automatching

I'm trying to develop a simple Turn based multiplayer game in android using Play games services. I followed all the steps in the docs: https://developers.google.com/games/services/android/turnbasedMultiplayer#implementing_auto-matching The only difference is that I don't want my players to be able to invite friends I want it to be purely Automatching. The game is only 2 player and it can only start ONCE 2 players have been matched. My problem is it doesn't seem to be automatching players. I run the app on 2 devices and they never seem to find each other... They both connect to the Play Games Services fine but they both just create a new game. Here is my code after I connect the GoogleApiClient.
#Override
public void onConnected(Bundle bundle) {
pDialog.dismiss();
Toast.makeText(this, "Connected", Toast.LENGTH_LONG).show();
showDialog("Matching players");
Bundle autoMatchCriteria = RoomConfig.createAutoMatchCriteria(1,1,0);
TurnBasedMatchConfig tbmc=TurnBasedMatchConfig.builder().
setAutoMatchCriteria(autoMatchCriteria).build();
Games.TurnBasedMultiplayer.createMatch(mGoogleApiClient,
tbmc).setResultCallback(new MatchInitiatedCallback(this));
}
Here is my MatchInitiatedCallback
public class MatchInitiatedCallback implements
ResultCallback<TurnBasedMultiplayer.InitiateMatchResult> {
private Context context;
public MatchInitiatedCallback(Context c) {
context = c;
}
#Override
public void onResult(TurnBasedMultiplayer.InitiateMatchResult
initiateMatchResult) {
pDialog.dismiss();
if(!initiateMatchResult.getStatus().isSuccess()) {
Toast.makeText(context, "ERROR: " +
initiateMatchResult.getStatus().getStatusCode(), Toast.LENGTH_LONG).show();
return;
}
TurnBasedMatch match = initiateMatchResult.getMatch();
if(match.getData() != null) {
Toast.makeText(context, "Player2 " + match.getData().toString(),
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(context, "Player1", Toast.LENGTH_LONG).show();
initGame(match);
}
}
}
Both devices show the TOAST that says: "Player1" and call the initGame(match) method which is here:
public void initGame(TurnBasedMatch match) {
String initialise = "initialised";
Games.TurnBasedMultiplayer.takeTurn(mGoogleApiClient,
match.getMatchId(),initialise.getBytes(Charset.forName("UTF-16")),
match.getParticipantId(Games.Players.getCurrentPlayerId(mGoogleApiClient))).
setResultCallback(this);
}
#Override
public void onResult(TurnBasedMultiplayer.UpdateMatchResult
updateMatchResult) {
if(updateMatchResult.getMatch().getStatus() ==
TurnBasedMatch.MATCH_STATUS_AUTO_MATCHING) {
Toast.makeText(this, "Still automatching",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Not automatching", Toast.LENGTH_LONG).show();
}
}
And once again they both Display the TOAST: "Still automatching"
What am I doing wrong. Why don't the devices automatch. Did I skip a step somewhere. Please help.
Try to change your initGame method so it specifies null for the next participant (to let Play Game services find a player for auto-matching):
public void initGame(TurnBasedMatch match) {
String initialise = "initialised";
Games.TurnBasedMultiplayer.takeTurn(
mGoogleApiClient,
match.getMatchId(),
initialise.getBytes(Charset.forName("UTF-16")),
null
).setResultCallback(this);
}
Also make sure to use two different google+ accounts on the two devices.
I tried your code and both devices said "Player1" and "Not automatching"(!). After changing to null, first device said "Player1" and "Still automatching" and second device said "Player2 [B#41b08830"
I think your problem is due to the way invitations as well as auto matching is handled by Play Game services. When hooking up participants to a TurnBasedMultiplayer match, invitations are sent to participants one by one. When you call takeTurn in the initGame method, you must specify the next participant to receive an invitation. When that participant has accepted the invitation, he must call takeTurn and specify the next participant to receive an invitation and so on. If you specify null, it means the next invitation goes to an automatched player.

SpotifySDK﹕ Got error 8 using SpotifySdkAndroid-1.0.0-beta3

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.

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