21

Hi I am creating an app which will play livestream.com's rtsp live channel. I am launching the player using intent within my app as following:

            iPlayer = new Intent(Intent.ACTION_VIEW); 
            //iPlayer.setType("video/*");
            iPlayer.setData(Uri.parse(videoUrl));  
            startActivity(iPlayer); 

When the media player is launched through my Application, the video performance is very poor. It stops for buffering every few seconds, plays for few seconds and pauses for buffering again.

ON the other hand, If I open the url in android browser (eg. http://m.livestream.com/abcalbania) it has a video tag on that page and triggers video player. THIS time, the video runs very smooth.

Any Idea why this might happen? And how this can be fixed?

  • I do not want to launch browser URL as intent.
  • This is done on Atmel cortex A9 chipset with Android 2.3.4
Dirk Jäckel
  • 2,979
  • 3
  • 29
  • 47
user1188837
  • 311
  • 1
  • 4

6 Answers6

1

The problem is caused by the codecs that probably are not supported by your player.

for example i have a video created with MPEG Audio codec along with the H.264 video codec.

if i launch the video through my Application the video runs smoothly, but if i launch a video in Ooyala Hook Player it has a very poor performance, it plays the video every 3 seconds, the reason is that the stream use MPEG audio codec instead of AAC Audio codec that is supported.

You will find the answer with:

what codecs are used to create de video, and what are supported by your player?

Jorgesys
  • 124,308
  • 23
  • 334
  • 268
0

Use this code for smooth STREAM

String videoUrl = "rtmp://mystream";
Intent i = new Intent(android.content.Intent.ACTION_VIEW);
i.setDataAndType(Uri.parse(videoUrl), "video/*");
startActivity(i);
Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
0

Why not you play this in your own activity, create activity and render the video view like

private String path2 = "rtsp://...";
Uri video = Uri.parse(path2);

mVideoView.setVideoURI(video);
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
mVideoView.postInvalidateDelayed(100);
mVideoView.start();

Also you can buffer before start playing maybe 5 secs and than successive buffering will be fast. you can control more thing by your own.

jitain sharma
  • 584
  • 5
  • 19
0

Android's MediaPlayer handle very well RTSP - don't open an external app - it's not necessary and product-wise wrong.

About your question - the browser might send another parameters to the video player that help the video play smooth, I didn't check it but it sounds like the only possible option for what you're describing. Example for the extra param might be the video resolution / encoding / size .. you can get all of them easily using MediaMetaDataRetriever.

If you don't want to use the native VideoView or MediaPlayer you can always add external player to your app, like libVLC or Vitamio.

I recommend of using Vitamio, is really easy to use and integrate. LibVLC is in native code, it means you'll have to build it using ndk and add its libs to your project. You can find here how to do that.

Nativ
  • 3,092
  • 6
  • 38
  • 69
-1

Android video view support RTSP urls well no need to pass intent to other application.Try out with this code, pass xml with declaration of video view and find it inside this activity.

public class VideoPlayer extends Activity
{

private VideoView mVideoView;            
String videoURL="";
static Utility utility;
static Context context;
//MediaController mediaController;
//int iCurrentpostion=0;
int counter=0;

@Override
public void onCreate(Bundle savedInstanceState) 
{         
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tab_video_player);          
        setupViews();
}
private void setupViews() 
    {
        context=VideoPlayer.this;
        //utility=new Utility(VideoPlayer.this);
        showProgressDialog("Please wait", "Loading video..");

         //videoURL=getIntent().getExtras().getString("url");             
         mVideoView=(VideoView)findViewById(R.id.xvdvwTab);
        // mediaController=new MediaController(context);             
        // mVideoView.setMediaController(mediaController);



       mVideoView.setOnPreparedListener(new OnPreparedListener() 
        {
           @Override
            public void onPrepared(MediaPlayer mp) 
            {

               utility.hideProgressDialog();

               mVideoView.start();                      
               mVideoView.requestFocus();

            }
        });

       mVideoView.setOnCompletionListener(new OnCompletionListener() 
        {

            @Override
            public void onCompletion(MediaPlayer mp) 
            {
                finish();
            }
        }); 


       mVideoView.setOnErrorListener(new OnErrorListener() 
       {

        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) 
        {
            utility.hideProgressDialog();
            return false;
        }
    });

       playVideoFile();      
    } 

private void playVideoFile() 
    {

            try 
            {                   
                mVideoView.setVideoURI(Uri.parse("your url"));
            }
            catch (Exception e) 
            {
                utility.hideProgressDialog();
                if (mVideoView != null) 
                {                   
                    mVideoView.stopPlayback();
                }
            }
        }
@Override
protected void onResume()
    {
        /*if(mVideoView!=null)
        {
            //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            mVideoView.requestFocus();
            if(iCurrentpostion!=0)
                mVideoView.seekTo(iCurrentpostion);
            mVideoView.start();         
        }
        super.onResume();*/
    }

@Override
protected void onDestroy() 
{
    try 
    {   
        if (mVideoView != null) 
        {               
            mVideoView.stopPlayback();
            mVideoView=null;                
        }
        super.onDestroy();
    } catch (Exception e) 
    {}              
}

public  void showProgressDialog(String title,String Message)
{   
        hideProgressDialog();
        progressDialog=new ProgressDialog(mActivity);
        progressDialog.setTitle(title);
        progressDialog.setMessage(Message);                         
        if(Constant.isActivityisRunning)
            progressDialog.show();

}
public void hideProgressDialog()
{
    if (progressDialog != null)
    {
        if (progressDialog.isShowing())
        {
            progressDialog.dismiss();
            progressDialog = null;
        }
    }
}

}

chet's
  • 193
  • 2
  • 8
  • Sigh. This code, just like everything else I can find, gives "error (100,0)". http://stackoverflow.com/questions/25215724/rtsp-1080p-live-streaming-android-client-gets-error-100-0 – Alain Collins Aug 24 '14 at 00:19
-1

I think play video by Asynchronously for better performance. My code is:

   private class myAsync extends AsyncTask<Void, Integer, Void> {
       int duration = 0;
    //int current = 0;
    @Override
    protected Void doInBackground(Void... params) {
        videoView.setOnPreparedListener(new OnPreparedListener() {

            public void onPrepared(MediaPlayer mp) {
                progressDialog.dismiss();
                videoView.seekTo(check);
                videoView.start();
                duration = videoView.getDuration();
            }
        });

        do {


            current = videoView.getCurrentPosition();
            System.out.println("duration - " + duration + " current- "
                    + current);


        }

            if (sync.isCancelled())
                break;

        } while (current != duration || current == 0);

        return null;
    }

}
Rahil Ali
  • 957
  • 10
  • 25