9

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();
            }
        }
    } 
Jonathan S.
  • 1,540
  • 1
  • 15
  • 26

4 Answers4

6

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();
Sasq
  • 348
  • 2
  • 7
  • 1
    this does not work for all phones for example htc phones has **User-Agent: HTC Streaming Player [operator-code] / 1.0 / htc_pyramid / 2.3.3** which does not have **stagefright** mentioned. – Samuel Jul 25 '11 at 02:42
2

With Android 2.3.5, now the media.stagefright.enable-player property does not exist in /system/build.prop

1

To get that information you can read the file /system/build.prop of your device. In this file there is a parameter named media.stagefright.enable-player. If that parameter is set to true, then stagefright is active, otherwise your device is using opencore.

Hussain
  • 5,446
  • 4
  • 38
  • 50
Jesus Oliva
  • 2,202
  • 13
  • 17
  • Looks promising, but Log.i(TAG,"Stagefright Enabled: " +System.getProperty("media.stagefright.enable-player")); //returns null on any device I test – Jonathan S. Jan 02 '11 at 19:26
  • That's true, sorry. Then you have to open the build.prop file and read the parameter. – Jesus Oliva Jan 02 '11 at 19:36
1

You might be able to detect if stagefright is enabled for streaming by searching for

media.stagefright.enable-http=true

instead of

media.stagefright.enable-player=true
alex
  • 11
  • 1