0

I am developing a Streaming MediaPlayer and I have 2 test devices:

1) Samsung Galaxy y (s5360) with Android version 2.3.5

2) Samsung Galaxy S2 (i9100g) with Android version 2.3.4

The MediaPlayer is working just fine with the "Galaxy y" but when I try to run it with the "Galaxy S2" it gives me this error:

setdatasource outside path in jni is �x@

And then it gives this error

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.MainActivity}: java.lang.NullPointerException

This is the code from the MediaPlayer:

**
  package com.adventure.agadir;

  import android.media.MediaMetadataRetriever;
  import android.media.MediaPlayer;
  import android.os.Bundle;
  import android.app.Activity;
  import android.content.Intent;
  import android.view.KeyEvent;
  import android.view.Menu;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.ImageView;
  import android.widget.TextView;

  public class MainActivity extends Activity {

private ImageView bannerView;
private int[] pub = {R.drawable.banner, R.drawable.pubnautic, R.drawable.pubquad};
private int i = 0;

private ImageView play;
private ImageView pause;
private ImageView stop;
private TextView title;
private MediaPlayer mediaPlayer;
private MediaMetadataRetriever retriever;
private String url = "http://support.k-designed.net/test-z/music/Accordossie.mp3";

private ImageView exit;

private ImageView wish;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    bannerView = (ImageView) findViewById(R.id.banner);

    play = (ImageView) findViewById(R.id.play);
    pause = (ImageView) findViewById(R.id.pause);
    stop = (ImageView) findViewById(R.id.stop);
    exit = (ImageView) findViewById(R.id.exit);
    title = (TextView) findViewById(R.id.title);

    retriever = new MediaMetadataRetriever();
    mediaPlayer = new MediaPlayer();

    wish = (ImageView) findViewById(R.id.wish);

    try {
        mediaPlayer.setDataSource(url);
        retriever.setDataSource(url);
        mediaPlayer.prepare();
    } catch (Exception e) {
        e.printStackTrace();
    }

    play.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                mediaPlayer.start();
                String out =  "Song: " + retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE) + " \nSinger: " + retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
                title.setText(out);
                play.setVisibility(ImageView.GONE);
                pause.setVisibility(ImageView.VISIBLE);

            } catch(Exception e) {
                e.printStackTrace();
            }
        }
    });

    pause.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            pause.setVisibility(ImageView.GONE);
            play.setVisibility(ImageView.VISIBLE);
            mediaPlayer.pause();
        }
    });

    stop.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            pause.setVisibility(ImageView.GONE);
            play.setVisibility(ImageView.VISIBLE);
            mediaPlayer.stop();
            mediaPlayer = null;
            retriever.release();
            retriever = new MediaMetadataRetriever();
            mediaPlayer = new MediaPlayer();
            try {
                mediaPlayer.setDataSource(url);
                retriever.setDataSource(url);
                mediaPlayer.prepare();
            } catch (Exception e) {
                e.printStackTrace();
            } 
        }
    });

    wish.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent wishIntent = new Intent(MainActivity.this, Wish.class);
            startActivity(wishIntent);

        }
    });

    exit.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            mediaPlayer.stop();
            onBackPressed();
        }
    });

    Runnable r = new Runnable() {

        @Override
        public void run() {
            bannerView.setImageResource(pub[i]);
            i++;
            if(i >= pub.length) {
                i = 0;
            }
            bannerView.postDelayed(this, 3000);
        }
    }; 
    bannerView.postDelayed(r, 3000);

}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        moveTaskToBack(true);
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

 }

**

Thanks for your help!

PS: This is the Logcat:

04-12 15:05:03.023: E/MediaPlayer-JNI(4377): setDataSource: outside path in JNI is �x@
04-12 15:05:06.734: E/AndroidRuntime(4377): FATAL EXCEPTION: main
04-12 15:05:06.734: E/AndroidRuntime(4377): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.adventure.agadir/com.adventure.agadir.MainActivity}: java.lang.NullPointerException
04-12 15:05:06.734: E/AndroidRuntime(4377):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
04-12 15:05:06.734: E/AndroidRuntime(4377):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
04-12 15:05:06.734: E/AndroidRuntime(4377):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-12 15:05:06.734: E/AndroidRuntime(4377):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
04-12 15:05:06.734: E/AndroidRuntime(4377):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-12 15:05:06.734: E/AndroidRuntime(4377):     at android.os.Looper.loop(Looper.java:130)
04-12 15:05:06.734: E/AndroidRuntime(4377):     at android.app.ActivityThread.main(ActivityThread.java:3691)
04-12 15:05:06.734: E/AndroidRuntime(4377):     at java.lang.reflect.Method.invokeNative(Native Method)
04-12 15:05:06.734: E/AndroidRuntime(4377):     at java.lang.reflect.Method.invoke(Method.java:507)
04-12 15:05:06.734: E/AndroidRuntime(4377):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
04-12 15:05:06.734: E/AndroidRuntime(4377):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
04-12 15:05:06.734: E/AndroidRuntime(4377):     at dalvik.system.NativeStart.main(Native Method)
04-12 15:05:06.734: E/AndroidRuntime(4377): Caused by: java.lang.NullPointerException
04-12 15:05:06.734: E/AndroidRuntime(4377):     at com.adventure.agadir.MainActivity.onCreate(MainActivity.java:76)
04-12 15:05:06.734: E/AndroidRuntime(4377):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-12 15:05:06.734: E/AndroidRuntime(4377):     atandroid.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
04-12 15:05:06.734: E/AndroidRuntime(4377):     ... 11 more
user1885868
  • 1,063
  • 3
  • 17
  • 31
  • is it occur when you press on the play button or when you starts the app? – Elior Apr 12 '13 at 11:53
  • how do you set the media player data source (the url variable in your code)? read here and see if it's help you http://stackoverflow.com/questions/9625680/mediaplayer-setdatasource-better-to-use-path-or-filedescriptor – Elior Apr 12 '13 at 11:57
  • Thanks @Elior for your response! It happens when I start the App. The URL variable is set to get Streaming from a different Server, something like this: private String url = "http://support.k-designed.net/test-z/music/Accordossie.mp3"; – user1885868 Apr 12 '13 at 14:15
  • can you post the all logcat? – Elior Apr 12 '13 at 14:18
  • OK @Elior I just did! – user1885868 Apr 12 '13 at 15:09
  • 2
    What is line 76? (MainActivity.java; should be in the onCreate Method) – DigCamara Apr 12 '13 at 15:12
  • as DigCamara mentioned.. can you post the MainActivity onCreate Method and tell us what is line 76? – Elior Apr 12 '13 at 15:17
  • OK DigCamara and @Elior I just published the whole code! The line 76 is the pause.setOnClickListener(new ...) method. – user1885868 Apr 12 '13 at 15:41
  • just for checking, try to add this pause.setClickable(true); before you're setting the clicklistener and see what happens – Elior Apr 12 '13 at 15:54
  • I just tried @Elior, unfortunately nothing happened! It's still the same! – user1885868 Apr 12 '13 at 16:00
  • It's weird because I see that you're initialize the pause button as (ImageButton)findViewByID(R...) so I don't know why it's crashes .. did you try to debug it? see if the pause button is null or not? – Elior Apr 12 '13 at 16:04
  • Yes @Elior the pause button is null – user1885868 Apr 12 '13 at 16:13
  • so here is your problem.. something is incorrect with the pauseButton initialize .. the findViewByID returns null.. – Elior Apr 12 '13 at 16:17
  • first of all try to clean your project and then build it again sometimes this helps.. take a look at this link http://stackoverflow.com/questions/5937962/findviewbyid-returns-null – Elior Apr 12 '13 at 16:22
  • Yes @Elior I forgot to put the Pause Button in the "activity_main.xml" layout. Now the app is showing up, yet it still gives the {setDataSource: outside path in JNI is �x@} error – user1885868 Apr 12 '13 at 16:24
  • private String url = "http://support.k-designed.net/test-z/music/Accordossie.mp3 I think it's because how you set the url path.. read the first link I gave you – Elior Apr 12 '13 at 16:33
  • I saw that link @Elior, the code given there is used to read from the mobile device, what I want is to read my music from a different streaming server. The code is working just fine in the "Galaxy y (s5360)" but not in the "Galaxy S2 (i9100g)" – user1885868 Apr 12 '13 at 16:44
  • maybe you need to add the link 'http:// ' or something like that? because the audio file is located at some folder at the server.. you need to exact path of the audio file which located at the server. see this answer at this link http://stackoverflow.com/questions/7441140/how-to-play-audio-file-from-server-in-android – Elior Apr 12 '13 at 20:33
  • ok ignore the last comment.. now I see that you located to the exact path.. here is the same issue as yours http://stackoverflow.com/questions/11198992/android-mediaplayer-streaming-issue-with-test-devices – Elior Apr 12 '13 at 20:41

0 Answers0