Android: play flv video stream from url

13.9k Views Asked by At

I currently have an app that records a video and uploads it to my server. after uploading the video, the app gets a response that holds a URL to the flv stream to the file.

when I try to open the stream in the android default video player (Videos) nothing happens, but when I used a different app (BSPlayer), it played the video perfectly. however, there is no way to force opening one app from Intent.ACTION_VIEW. here is the code for the function that receives the response from the server:

@Override
protected void onResponseReceived(int requestType, int status, Object resp) {
    switch (requestType) {
    case CLIP_DETAILS: {
        if (status == RESPONSE_OK) {
            String token1 = ((ResponseObject_ClipDetails) resp).m_token1;
            String token2 = ((ResponseObject_ClipDetails) resp).m_token2;
            String url = getClipURL(token1, token2);

            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            i.setType("video/flv");
            startActivity(i);
        }

    }
        break;
    }
}

is there a way to show .flv videos in my android app?

2

There are 2 best solutions below

2
On

Actually, there is a way to force opening specific app.

This answer shows how to do that. https://stackoverflow.com/a/10035789/375929

Just find out BSPlayer's package name and use it to filter the apps to open your video. Of course, you'll also need to handle the case when there's no BSPlayer installed. I suggest using queryIntentActivities() - if it returns an empty list, tell user they need to install BSPlayer and launch the corresponding play store link.

Short of asking user to install a 3rd party app, you can also implement your own flv player via WebView, although you'll still need the user to have flash player (but that's somewhat different, everybody knows what flash player is, so it shouldn't be a problem to ask user to install it)

I found two tutorials on how to do that: Problem to load flv video in webview and http://www.synesthesia.it/playing-flash-flv-videos-in-android-applications

0
On

You can use vitamio.

Media formats

Many audio and video codecs are packed into Vitamio beside the default media format built in Android platform, some of them are listed below.

  • divx/xvid
  • wmv
  • flv
  • ts
  • rmvb
  • mkv
  • mov
  • m4v
  • avi
  • mp4
  • 3gp

Vitamio SDK for Android developers

You can download the jar file to use with your project here. (Vitamio-SDK.7z)

For Android developers

Here is a demo project which uses the vitamio.jar. (Vitamio-Demo.7z)

Vitamio provides the similiar interfaces with Android default MediaPlayer framework. If you're using android.media.MediaPlayer in your project, just grab the vitamio.jar from above, then add it to your project's libs, and replace the import of android.media.MediaPlayer with io.vov.vitamio.MediaPlayer.

Besides the default interfaces from Android MediaPlayer, Vitamio provides more APIs, please refer the javadoc in the library.