I need to be when you press the buttons in the usual android I could switch to music in my standard audio player for android while the music is playing. How can you interact with a standard audio player for android?
Music player is not standard thing on Android and vendors can come with different app than others (i.e. Sony is good exapmple). Controlling media app can be doable but final effect depends on what app is really installed (and used, as user can have more than one). You may be able to control some, but other may remain immune to your attempts. You can try this code - will work for Google Music for example):
public static final String SERVICECMD = "com.android.music.musicservicecommand";
public static final String CMDNAME = "command";
public static final String CMDSTOP = "stop";
AudioManager mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
if(mAudioManager.isMusicActive()) {
Intent i = new Intent(SERVICECMD);
i.putExtra(CMDNAME , CMDSTOP );
YourApplicationClass.this.sendBroadcast(i);
}
other commands are
public static final String CMDTOGGLEPAUSE = "togglepause";
public static final String CMDPAUSE = "pause";
public static final String CMDPREVIOUS = "previous";
public static final String CMDNEXT = "next";
Commands are taken from android/music/MediaPlaybackService.java
Related
Checking out the MediaController documentation, I noticed that there is a function called sendCommand(...), which requires three parameters:
command: String;
args: Bundle;
cb: ResultReceiver.
But examples of how to use that method are nowhere to be found.
What are the available MediaController#sendCommand(...) default commands and acceptable argument keys and values types?
For example, checking PlaybackState documentation, we can find a constant called ACTION_PLAY_FROM_MEDIA_ID which description is as follows:
Indicates this session supports the play from media id command
This leads us to think that MediaController#sendCommand(...) is able to change a MediaSession's current media by sending it the media ID. How can we do it?
It's known that Google Play Music App's MediaController shares its Media Queue through MediaController#getQueue function.
You can find Commands constants in MediaControllerCompat.
They actually are:
public static final String COMMAND_GET_EXTRA_BINDER =
"android.support.v4.media.session.command.GET_EXTRA_BINDER";
public static final String COMMAND_ADD_QUEUE_ITEM =
"android.support.v4.media.session.command.ADD_QUEUE_ITEM";
public static final String COMMAND_ADD_QUEUE_ITEM_AT =
"android.support.v4.media.session.command.ADD_QUEUE_ITEM_AT";
public static final String COMMAND_REMOVE_QUEUE_ITEM =
"android.support.v4.media.session.command.REMOVE_QUEUE_ITEM";
public static final String COMMAND_REMOVE_QUEUE_ITEM_AT =
"android.support.v4.media.session.command.REMOVE_QUEUE_ITEM_AT";
public static final String COMMAND_ARGUMENT_MEDIA_DESCRIPTION =
"android.support.v4.media.session.command.ARGUMENT_MEDIA_DESCRIPTION";
public static final String COMMAND_ARGUMENT_INDEX =
"android.support.v4.media.session.command.ARGUMENT_INDEX";
For some basic usage samples u can check out its methods, like:
#Override
public void removeQueueItem(MediaDescriptionCompat description) {
long flags = getFlags();
if ((flags & MediaSessionCompat.FLAG_HANDLES_QUEUE_COMMANDS) == 0) {
throw new UnsupportedOperationException(
"This session doesn't support queue management operations");
}
Bundle params = new Bundle();
params.putParcelable(COMMAND_ARGUMENT_MEDIA_DESCRIPTION, description);
sendCommand(COMMAND_REMOVE_QUEUE_ITEM, params, null);
}
I have a project https://github.com/njovy/AppRTCDemo. This project works 1 -1 calls. I modified the PeerConnectionClient.class:
private static final PeerConnectionClient instance = new PeerConnectionClient();
// private final PCObserver pcObserver = new PCObserver();
private final PCObserver[] pcObservers = new PCObserver[MAX_CONNECTIONS];
// private final SDPObserver sdpObserver = new SDPObserver();
private final SDPObserver[] sdpObservers = new SDPObserver[MAX_CONNECTIONS];
private final LooperExecutor executor;
private static final int MAX_CONNECTIONS = 3;
private PeerConnectionFactory factory;
private PeerConnection[] peerConnections = new PeerConnection[MAX_CONNECTIONS];
PeerConnectionFactory.Options options = null;
private VideoSource videoSource;
private boolean videoCallEnabled;
private boolean audioCallEnabled;
private boolean preferIsac;
private boolean preferH264;
private boolean videoSourceStopped;
private boolean isError;
private Timer statsTimer;
private VideoRenderer.Callbacks localRender;
private VideoRenderer.Callbacks[] remoteRenders;
private SignalingParameters signalingParameters;
private MediaConstraints pcConstraints;
private MediaConstraints videoConstraints;
private MediaConstraints audioConstraints;
private MediaConstraints sdpMediaConstraints;
private PeerConnectionParameters peerConnectionParameters;
// Queued remote ICE candidates are consumed only after both local and
// remote descriptions are set. Similarly local ICE candidates are sent to
// remote peer after both local and remote description are set.
private LinkedList<IceCandidate>[] queuedRemoteCandidateLists = new LinkedList[MAX_CONNECTIONS];
private PeerConnectionEvents events;
private boolean[] isConnectionInitiator = new boolean[MAX_CONNECTIONS];
private SessionDescription[] localSdps = new SessionDescription[MAX_CONNECTIONS]; // either offer or answer SDP
private MediaStream mediaStream;
private int numberOfCameras;
private VideoCapturerAndroid videoCapturer;
// enableVideo is set to true if video should be rendered and sent.
private boolean renderVideo;
private VideoTrack localVideoTrack;
private VideoTrack[] remoteVideoTracks = new VideoTrack[MAX_CONNECTIONS];
as here https://pastebin.com/c0YCHS6g. My Activity for call: https://pastebin.com/8RVwVZRq
Android WebRTC - create 1-N calls, what is the value of N here?
If N > 4 you need to use a media relay servers(SFU/SVC) servers, otherwise mobile will die !!
For N remote participants, WebRTC will do N times encoding (it will eat CPU & battery N times) and to relay stream to N participants it will consume N times bandwidth (you can't imagine it in 3G/4G).
Choose a media server based on your use case from Janus/Jitsi/Kurento/Licode/red5/switchrtc/wowza and many more.
If N <= 4:
you need to refactor peerConnectionClinet into two parts.
1. Singleton Factory: Main peerConnectionFactory & MediaStream/MediaTracks
2. PC Instances: create a peerConnection from the Singleton Factory and add the same stream to all the instances. This pc instance is responsible for offer/answer/candidates exchange for each endpoint.
I am building an app based on the mobile hub sample app. The sample-app has the API keys stored in a class file AWSconfiguration:
public class AWSConfiguration {
// AWS MobileHub user agent string
public static final String AWS_MOBILEHUB_USER_AGENT =
"MobileHub ********* aws-my-sample-app-android-v0.16";
// AMAZON COGNITO
public static final Regions AMAZON_COGNITO_REGION =
Regions.fromName("us-east-1");
public static String AMAZON_COGNITO_IDENTITY_POOL_ID = "us-east-************6";
// Google Client ID for Web application
public static String GOOGLE_CLIENT_ID ="";//"*********************.apps.googleusercontent.com";
public static final Regions AMAZON_DYNAMODB_REGION =
Regions.fromName("us-east-1");
public static String AMAZON_COGNITO_USER_POOL_ID = "************";
public static String AMAZON_COGNITO_USER_POOL_CLIENT_ID = "*************";
public static String AMAZON_COGNITO_USER_POOL_CLIENT_SECRET = "*************";
private static final AWSMobileHelperConfiguration helperConfiguration = new AWSMobileHelperConfiguration.Builder()
.withCognitoRegion(AMAZON_COGNITO_REGION)
.withCognitoIdentityPoolId(AMAZON_COGNITO_IDENTITY_POOL_ID)
.withCognitoUserPool(AMAZON_COGNITO_USER_POOL_ID,
AMAZON_COGNITO_USER_POOL_CLIENT_ID, AMAZON_COGNITO_USER_POOL_CLIENT_SECRET)
.build();
/**
* #return the configuration for AWSKit.
*/
public static AWSMobileHelperConfiguration getAWSMobileHelperConfiguration() {
return helperConfiguration;
}
}
It seems unsafe to store the client secret key this way. What are the risks?
I experiemnted with hiding the keys in JNI files but could not find the proper entry point in the activity to set the keys before they are called from the mobile helper.
Storing in clear text is generally a bad idea, as you guessed. You could use the android keystore, store it encrypted (the stronger the key, the better), obfuscate it with some unique identifier of your device, or access it via some API you control and secure. It's possible to use some other solution, or a combination of the above possibilities. The final decision comes down to you and what your app needs/abilities are, but there's a few ways to hide it.
SharedPreferences.Editor can be a solution.
Password or something like this are stored in SharedPreferences.
I am using YouTubeAndroidPlayerApi - 1.2.1, to show Youtube videos in my application. I get the url's from backend and they come in different formats. For example,
public static final String DOMAIN_1 = "https://www.youtube.com/watch?v=";
public static final String DOMAIN_2 = "http://www.youtube.com/watch?v=";
public static final String DOMAIN_3 = "https://youtu.be/";
public static final String DOMAIN_4 = "http://www.youtube.com/embed/";
public static final String DOMAIN_5 = "https://www.youtube.com/embed/";
All the above urls have VideoID at the end, and I am able to get VideoID and use,
Intent intent = YouTubeStandalonePlayer.createVideoIntent((Activity) activity,
Const.YouTube.API_KEY, videoId, 0,
true, true);
to play them. But my problem is, there are also urls such as,
https://www.youtube.com/watch?t=15&v=video_id
https://www.youtube.com/watch?v=video_id&list=PL1RpYLGwB6WM409EJBVM1MS9bs3httFse&index=1
and since there are other characters in it, I couldn't extract the videoID.
Is there a way I can use URL with createVideoIntent() or is there any other way i can use URLs to work with YouTubeAndroidPlayerApi.
[EDIT]
If i can't use URL, can someone help me with getting a regex, for extracting videoID from the above Urls?
Use regular expression to cut off the rest of the url
After I followed all the steps for the push notification sample app. I wasn't able to send a notifaction to myself. I could send a pushmessage from my PC to my phone, but when I use the button Send myself a Notification nothing happens.
I am using Android sdk
After starting the app I do see that my Device is Registerd
Here is my settings.java
package com.ganyo.pushtest;
/** Change these values to match your setup! */
public class Settings {
static final String UNASSIGNED_ORG_VALUE = "";
// Google Client Id from Google API Console
static final String GCM_SENDER_ID = "xxxxxxxxxxxxx";
// Notifier Name in App Services
static final String NOTIFIER = "androidDev";
static final String API_URL = "https://api.usergrid.com";
static final String ORG = "xxxxxxx";
static final String APP = "sandbox";
// set these if you want to use a user login
static final String USER = null;
static final String PASSWORD = null;
}
I'm not sure what the UNASSIGNED_ORG_VALUE should be.
Thx in advance.
No need to assign any value to UNASSIGNED_ORG_VALUE. It's only used to check that you've entered the other values.
Please check your Android logs as well as the Apigee Console to see what error messages might have been generated during your push attempt. This will help you debug the issue.
Finally, you could try providing your notifier name here in all lowercase. (Note: This shouldn't generally be necessary, but I've heard there may be a issue that affects notifier name resolution.)