If you elevate permissions you can also play URLs from inside a Kindlet, using the reflection technique described here:
https://www.mobileread.com/forums/sho...79&postcount=4
Here is a method that plays a mp3 from a URL. Setting up callbacks should be possible, although tedious, using reflection.
Code:
private void playAudioFromUrlWrapper (final URL url) {
setDescription("Initiating connection");
final ConnectivityHandler handler = new ConnectivityHandler() {
public void connected() {
try {
playAudioFromUrl(url);
} catch (IllegalStateException ise) {
ise.printStackTrace();
}
}
public void disabled(NetworkDisabledDetails details) {
;
}
};
context.getConnectivity().submitSingleAttemptConnectivityRequest(handler, true);
}
private void playAudioFromUrl (URL url) {
Class contextClass = context.getClass();
Method[] methods = contextClass.getDeclaredMethods();
Method audioMethod = methods[1];
Object audioManagerObject;
Class audioManagerClass;
try {
audioManagerObject = audioMethod.invoke(context, new Object[0]);
audioManagerClass = audioManagerObject.getClass();
Method[] audioManagerMethods = audioManagerClass.getDeclaredMethods();
Method createAudioPlayerMethod = audioManagerMethods[10];
Class mediaSourceClass = createAudioPlayerMethod.getParameterTypes()[0];
Constructor[] mediaSourceConstructors = mediaSourceClass.getConstructors();
//Constructor mediaSourceInputStreamConstructor = mediaSourceConstructors[3];
Constructor mediaSourceUrlConstructor = mediaSourceConstructors[1];
Object[] mediaSourceArgs = new Object[1];
mediaSourceArgs[0] = url;
Object mediaSourceObject = mediaSourceUrlConstructor.newInstance(mediaSourceArgs);
Object[] createAudioPlayerArgs = new Object[1];
createAudioPlayerArgs[0] = mediaSourceObject;
Object audioObject = createAudioPlayerMethod.invoke(audioManagerObject, createAudioPlayerArgs);
Class audioClass = audioObject.getClass();
Method[] audioMethods = audioClass.getDeclaredMethods();
Method playMethod = audioMethods[12];
playMethod.invoke(audioObject, new Object[0]);
} catch (IllegalArgumentException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
} catch (InvocationTargetException e1) {
e1.printStackTrace();
} catch (InstantiationException e1) {
e1.printStackTrace();
}
}