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

  • SEARCH
  • Home
  • 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 8207687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:04:38+00:00 2026-06-07T09:04:38+00:00

I have a MediaPlayerActivity with the following code: This code basically tries to get

  • 0

I have a MediaPlayerActivity with the following code:
This code basically tries to get a video stream from a http url and load it but for some reason it keeps crashing.

public class MediaPlayerActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        this.setContentView(R.layout.video_player);
        SurfaceView v = (SurfaceView) findViewById(R.id.surface_video); 
        SurfaceHolder holder = v.getHolder(); 
        holder.setFixedSize(400,300); 

        MediaPlayer mp = MediaPlayer.create(this, Uri.parse("http://stream-url.com/playlist.m3u8")); 
        mp.setDisplay(holder);
        //mp.setAudioStreamType(2); 
        try {
            //mp.prepare();
            mp.start();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    }

}

video_player.xml:

<?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" 
> 
<SurfaceView android:id="@+id/surface_video" 
android:layout_width="250px" 
android:layout_height="250px"> 
</SurfaceView> 
<LinearLayout 
android:orientation="horizontal" 
android:layout_height="wrap_content" 
android:layout_width="fill_parent" 
android:padding="10dip" 
> 
</LinearLayout> 
</LinearLayout> 

When I go to this activity using the following code it crashes:

Intent myIntent = new Intent(HomeActivity.this, MediaPlayerActivity.class);
                    HomeActivity.this.startActivity(myIntent);

What am I doing wrong?

  • 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-07T09:04:40+00:00Added an answer on June 7, 2026 at 9:04 am

    Without logs, two suggestions:

    1. try implementing SurfaceHolder.Callback.surfaceCreated().
    2. try using MediaPlayer.create() that accepts SurfaceHolder

    Details of (1)

    Maybe your surface is not yet created when you call start(). You should use MediaPlayer.setDisplay() and MediaPlayer.start() only after surface is created. To do this, you should add overrideSurfaceHolder.Callback.surfaceCreated()`. For example, your code could look like this.

    public class MediaPlayerActivity extends Activity implements SurfaceHolder.Callback {
        MediaPlayer mp; 
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            this.setContentView(R.layout.video_player);
            SurfaceView v = (SurfaceView) findViewById(R.id.surface_video); 
            SurfaceHolder holder = v.getHolder(); 
            holder.setFixedSize(400,300);
            holder.addCallback(this). 
    
            mp = MediaPlayer.create(this, Uri.parse("http://stream-url.com/playlist.m3u8")); 
    
        @Override
        public void surfaceCreated(SurfaceHolder holder) {
    
            mp.setDisplay(holder); 
            try {
                mp.start();
            } catch (IllegalStateException e) {
                e.printStackTrace();
            }
        }
    }
    

    Details of (2)

    There seems to be other MediaPlayer.create() that accepts SurfaceHolder as one of the arguments – you could try it: http://developer.android.com/reference/android/media/MediaPlayer.html#create(android.content.Context, android.net.Uri, android.view.SurfaceHolder)

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

Sidebar

Related Questions

Have converted devise new session from erb to Haml but doens't work, this is
Have a look at this url: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:jquery_ui_methods#column_chooser I have got the Column Chooser dialog
Have you managed to get Aptana Studio debugging to work? I tried following this,
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =
Have added the following code to my SQL query: (Note cut down version) DECLARE
In my application, I have an activity play http live streaming video in landscape
Have a look at the following code to find X^y. /* Find exponent in
have a php code like this,going to convert it in to C#. function isValid($n){
Have the following code. The height is variable so the height of the floating

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.