Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7711041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:16:35+00:00 2026-06-01T01:16:35+00:00

I have a problem with playing video in mediaplayer. I have a sound but

  • 0

I have a problem with playing video in mediaplayer. I have a sound but no video. I tried everything and can’t find solve. Or maybe you know how to play sdp file in videoview? Here’s the code:

public class TestStream1 extends Activity implements Callback{
MediaPlayer mMediaPlayer;
String SrcPath = "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov";
private SurfaceView mPreview;
private SurfaceHolder holder;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mPreview = (SurfaceView) findViewById(R.id.surface);
       holder = mPreview.getHolder();
       holder.addCallback(TestStream1.this);
       holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

       holder.setFixedSize(400,300); 
       mMediaPlayer = new MediaPlayer(); 
       try{
           mMediaPlayer.setDataSource(SrcPath);
           mMediaPlayer.setDisplay(holder);
           mMediaPlayer.prepare();
           mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
           mMediaPlayer.start(); 

       }catch(Exception e){
           Toast .makeText( TestStream1.this, "Fail", Toast.LENGTH_LONG).show();
       }

}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
        int height) {
    // TODO Auto-generated method stub

}
@Override
public void surfaceCreated(SurfaceHolder holder) {
    // TODO Auto-generated method stub

}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    // TODO Auto-generated method stub

}
}

EDIT: layout file

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  >
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello" />
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <SurfaceView
            android:id="@+id/surface"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </LinearLayout>
</LinearLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T01:16:36+00:00Added an answer on June 1, 2026 at 1:16 am

    Some videos cannot be played in mediaplayer, if it doesn’t have the codec for its a/v or it is too complex or badly interleaved (Look at Logcat for signs about some). Could be one or more reasons. To make sure the mediaplayer can play the type of video you are asking it to play, save a video file of the same a/v codec and extension to your sd card and then try to play it using the default media player.
    Meanwile, try using a videoView to check the video can be played.Your code seems all right.

    Try this code :

    package a.b;

    public class TestStream1 extends Activity implements Callback{
        MediaPlayer mMediaPlayer;
        String SrcPath = "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov";
        private SurfaceView mPreview;
        private SurfaceHolder holder;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            mPreview = (SurfaceView) findViewById(R.id.surface);
            holder = mPreview.getHolder();
            holder.addCallback(TestStream1.this);
            holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    
            holder.setFixedSize(400,300); 
            mMediaPlayer = new MediaPlayer(); 
    
        }
        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width,
                int height) {
            // TODO Auto-generated method stub
    
        }
        @Override
        public void surfaceCreated(SurfaceHolder holder) {
            // TODO Auto-generated method stub
            try{
                mMediaPlayer.setDisplay(holder);
                mMediaPlayer.setDataSource(SrcPath);
                mMediaPlayer.prepare();
                mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                mMediaPlayer.start(); 
    
            }catch(Exception e){
                Toast .makeText( TestStream1.this, "Fail", Toast.LENGTH_LONG).show();
            }
    
        }
        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {
            // TODO Auto-generated method stub
    mMediaPlayer.release();
        }
    }
    

    SurfaceHolders are created ansynchronously, so we have to wait until the surface has been created and then assign the returned surface holder object .
    And I am using the following layout:

        <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      >
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <SurfaceView
                android:id="@+id/surface"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </LinearLayout>
    

    The above solution should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Xcode 4.3 and i have a problem with playing sound... I
I have been playing about with canvas, but have stumbled across a problem. When
I basically have the same problem in this questions: Flash Video still playing in
I have a problem about html5 video playing on IE 9 I'm using .mov
I have no problem playing the video, just cant seem to get my label
Playing with Disqus for commenting, but the problem is that we have a Silverlight
I have a problem playing mp4 video files on the Droid2 with android 2.2
I have a problem with playing a video in HTML5 and the ended Event.
I'm currently playing with reflection and I have problem with my short code: public
I've been playing around with the splitting of atoms and have a problem with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.