Android TurnBasedMultiplayer calling takeTurn() doesnt generate a onTurnBasedMatchReceived() - android

I am writing a Multiplayer game using Google's TurnBasedMultiplayer API and calling takeTurn(). I have three players in the game, and besides the player who is calling takeTurn, I am finding that one player receives the update and onTurnBasedMatchReceived() is correctly called, yet the other player doesn't receive the update, onTurnBasedMatchReceived() is not called.
Can someone supply me with a possible reason not all players are receiving the updates? I note that the player who doesn't receive the update needs to go back to the Match Inbox and choose the relevant match again, and then it can be seen that the game is in fact updated.

Is the player who is not receiving the updates completely in the match? A player who hasn't accepted an invitation won't receive calls to onTurnBasedMatchUpdated.
Additionally, when a player receives an invitation, this comes to an invitation listener, not a match updated listener. If you're trying to use the match updated listener for both, that would also explain why you're not getting an update.

Have you activated the listener. I use code like this on my main activity...
public class GameScreen extends Activity implements OnInvitationReceivedListener,
OnTurnBasedMatchUpdateReceivedListener {
...
}

Related

Publishing App Not Triggering OnSteamReceived Event

I have two Android devices running separate TokBox apps which are trying to communicate with each other through video chat. I am having a problem in getting the OnStreamReceived event from one of my application which is publishing the video chat. But the application that subscribes the video triggers the event. I need the event to be triggered on the publishing side. Can anybody let me know the reason? Thanks.
Tokbox QA staff here.
Not sure what you mean with "separate Tokbox apps", but, if you use the same API Key for both ends, and you connect to the same session, the OnStreamReceived event would be received by the subscribers, not the publisher. This event will be triggered when another client publishes a stream, which means that the subscriber will not trigger the event. You can find further information here:
https://tokbox.com/developer/guides/subscribe-stream/android/#detect_streams
TokBox Developer Evangelist here.
As Fran mentioned, the onStreamReceived will only fire when another client in the session publishes. If you want to know when the publisher has started to publish from the publisher's perspective, please use this method:
public void onStreamCreated(PublisherKit publisherKit, Stream stream) {
// publishing - do something
}
About half the time the Publisher.StreamCreated event doesn't fire. The breakpoint simply isn't hit and the subscribers are therefore not notified since the publisher isn't sending anything. It's really hit or miss and frustrating.

How to handle failed AudioFocus requests in Android?

I am working on an application that has media playing features.
I would like to honor AudioFocus. I first request AudiFocus:
audioManager.requestAudioFocus(new CustomOnAudioFocusChangeListener(), AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
This call returns either AUDIOFOCUS_REQUEST_FAILED or AUDIOFOCUS_REQUEST_GRANTED.
I guess I shouldn't start playback if I receive AUDIOFOCUS_REQUEST_FAILED. But then what to do?
Will my CustomOnAudioFocusChangeListener be notified when focus becomes available or is it only when you got AUTOFOCUS_REQUEST_GRANTED that it starts getting updates?
Should I inform the user and ask him to try again later? Or retry programmatically after some time?
Thanks in advance
What to do depends on how you want your app to react. You shouldn't start playing, you may want to message your user. Or if its something non-critical, you may silently ignore the failure and move on.
I believe you only get updates on the listener on success. You get the updates then so if you're lowered you can choose to duck your output or pause until you regain.

Google ChromeCast Playlist from Android Device

I'm using a sample app for the RemotePlaybackClient from #commonsware to play a video from a url to Google ChromeCast dongle, the app works like a charm but I would like to implement a playlist, any idea how to send a playlist to ChromeCast from an Android device?
As usual, I don't need code, just links, tutorials, etc... Tks.
Are you using a custom receiver?
If so, you can pass a json to such receiver with your playlist and manage that list with a playback state.
you might try looking at "mediaList" object here. Thats your playlist object.
This is a totally different project (not mediaRouter api but ccl instead) that i used because i wanted to implement a playlist and wanted to NOT take on my own receiver app. I wanted to see whether the default receiver could collaborate with an existing github sender sample - altered slightly to manipulate both a playList implemented in the "mediaList" AND to send appropriate and successive PLAY instructions to the default recieiver app when that app's state as relayed in normal "consumer" message traffic indicated state=ready.
D/ccl_VideoCastManager(31057): onApplicationStatusChanged() reached: Ready To Cast
So, when the default receiver fires the "ready" message, the senderApp can just call getNext to return an entry from "mediaList" and then send a "play(mediaInfo.entry)" to the default receiver.
onApplicationStatusChanged() is the interface used by the ccl to commmunicate/ sync player state between the local/remote players. When the default-remote-state changes to "ready to cast" you can use "VideoCastManager" and its base class to select the next MediaInfo entry and format a message for the remote to play it...
this.startCastControllerActivity(this.mContext, nextMediaInfo, 0, true);
code above from sender/ccl base tells the receiver to play the item that the sender has determine is next from list.
Note : i was advised to implement the playlist on a custom receiver app that i would write. Im not that ambitious and found a very simple hack on the sender/ccl classes that was reliable enough for me.

Casting video to ChromeCast by Youtube app

I tried using a Android phone to cast to Chromecast device by Youtube app. I added some Videos to queue, then I used another phone to cast to Chromecast device. The second one automatically knows the videos added to queue on the first one.
I don't know how Youtube app can do this?
EDIT I guess Youtube app uses one custom data channel besides Media channel. When Video is added to queue, sender app will send somethings (eg: videoId) to receiver. Receiver will save it in array of video ID. When another phone connects to Chromecast device, It'll receiver array of video ID from the receiver. Can anyone give other solutions? Thanks
I guess what you are asking is how you can create a play list, potentially shared by multiple devices. If that is the case, you have a couple of choices:
keep the playlist in the receiver: this is the simplest option. This will be a simple array on the receiver, kept in memory, which will go away when application ends. A custom receiver is required and it can implement the methods such as "append, insert, get, clear, ... to provide what the senders need. When each sender connects, it can ask (calling 'get' for example) for the current "queue" and then can modify the queue by other methods such as 'clear', 'append', 'insert', .... Note that there is no long-term persistence on the receiver (local storage is available but will be cleared as son as the app is gone).
keep the playlist in the cloud: you need to do most of the things that you do in the previous option but you also persist the playlist to the cloud; the advantage is that playlist lasts beyond the life of a session (this may or may not be desired). In addition, sender apps can potentially get the playlist fro the cloud directly, if needed.
The important thing is that the main storage for your playlist is not your sender devices; they don't know (and shouldn't know) abut the presence of other senders in the eco-system.
On the receiver side, we recently published a simple sample that sows how the notion of (local) playlist can be implemented; that is a simplified example but is enough to show that with minimal work, you can take advantage of the Media Channel; for more sophisticated handling of a shared queue, you definitely need an out-of-bound channel/namespace to handle all the additional api's that I mentioned above.

How to automatically answer call and play prerecorded sound out to the caller and DTMF on Android

Could it be possible now, which we can develop an Android application having the following requirement for its working steps
Automatic receive the call, then
Play some sound out to the caller, wait for DTMF response, then
Record the caller sound (in the case that they permit, by pressing 1 as DTMF response)
Callee can play back the recoreded sound later.
Thank for all answers in advance .....
Hey I am also making same application...for Automatic receive call you need to change Source Code of android. I have done it successfully with froyo 2.2. There is method answerCall(Phone phone) in PhoneUtils.java file with that you can automatic receive call.
I am also searching for DTMF....but till now i didn't get anything which can be helpful....for DTMF decoding....
the first point seems possible. check the state of call if it is ringing state the program can auto attend it for you..you can find more information in this link.
http://www.devlper.com/2010/08/detecting-incoming-and-outgoing-calls-in-android/
http://prasanta-paul.blogspot.com/2010/09/call-control-in-android.html

Categories

Resources