ストリーミング MediaPlayer を開発しており、2 つのテスト デバイスがあります。
1) Android バージョン 2.3.5 を搭載した Samsung Galaxy y (s5360)
2) Android バージョン 2.3.4 を搭載した Samsung Galaxy S2 (i9100g)
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