0

我正在开发一个流媒体播放器,我有 2 个测试设备:

1) 三星 Galaxy y (s5360) 安卓版本 2.3.5

2) 三星 Galaxy S2 (i9100g) 安卓版本 2.3.4

MediaPlayer 在“Galaxy y”上运行得很好,但是当我尝试用“Galaxy S2”运行它时,它给了我这个错误:

setdatasource outside path in jni is �x@

然后它给出了这个错误

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

这是来自 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;
}

 }

**

谢谢你的帮助!

PS:这是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
4

0 回答 0