I need to determine if a mediaplayer is using the opencore media framework, so that I can disable seeking for my streams. The opencore framework appears to fail silently with seeking, which I am having a hard time believing they allowed into production, but that seems the case nonetheless.
I wish it were as simple as determining their SDK version, but droid phones that have api 8 seem to use opencore still, so doesn't seem to be a good option. Any ideas?
EDIT:
After the response from Jesus, I came up with this code. It seems to work well in my tests so far. If anybody doesn't think it is a sound method for seeking streams, let me know
if (Build.VERSION.SDK_INT < 8) //2.1 or earlier, opencore only, no stream seeking
mStreamSeekable = false;
else { // 2.2, check to see if stagefright enabled
mStreamSeekable = false;
try {
FileInputStream buildIs = new FileInputStream(new File("/system/build.prop"));
if (CloudUtils.inputStreamToString(buildIs).contains("media.stagefright.enable-player=true"))
mStreamSeekable = true;
} catch (IOException e) { //problem finding build file
e.printStackTrace();
}
}
}
That method does not work on the Samsung Galaxy S, which says Stagefright is enabled but does not use it, at least not for streaming. A more secure check is to open a local socket and connect the MediaPlayer to it and see what it reports as User-Agent.
For instance, this is what I see on my Samsung Galaxy S and the 2.2 Emulator;
Galaxy S: User-Agent: CORE/6.506.4.1 OpenCORE/2.02 (Linux;Android 2.2)
Emulator: User-Agent: stagefright/1.0 (Linux;Android 2.2)
In one thread, do something like this;
volatile int socketPort;
ServerSocket serverSocket = new ServerSocket(0);
socketPort = serverSocket.getLocalPort();
Socket socket = serverSocket.accept();
InputStream is = socket.getInputStream();
byte [] temp = new byte [2048];
int bsize = -1;
while(bsize <= 0) {
bsize = is.read(temp);
}
String res = new String(temp, 0, bsize);
if(res.indexOf("User-Agent: stagefright") >= 0) {
// Found stagefright
}
socket.close();
serverSocket.close();
And like this in another thread (makes the blocking accept() call above return);
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(String.format("http://127.0.0.1:%d/", socketPort));
mp.prepare();
mp.start();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With