每当我在 android 中执行 mp.stop 时,我都会遇到此错误,基本上是带有 body RING:(password) 来播放音频和 STOP:(password) 来停止音频的短信。该剧运行良好,但没有停止。
MediaPlayer mp = MediaPlayer.create(context, R.raw.braincandy);
if (correctSHA1 != null) {
if (intent.getAction().equals(SMS_RECEIVED)) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object pdus[] = (Object[]) bundle.get("pdus");
SmsMessage smsMessage[] = new SmsMessage[pdus.length];
for(int i = 0; i < pdus.length; i++) {
smsMessage[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
if (smsMessage[i].getMessageBody().contains("RING:")) {
String[] tokens = smsMessage[i].getMessageBody().split(":");
Log.v(TAG, "RING SMS Message keyword detected");
if (tokens.length >= 2) {
Log.v(TAG, "Token 1: " + tokens[0]);
Log.v(TAG, "Token 2: " + tokens[1]);
String SHA1hash = PhoneFinder.getSHA1(tokens[1]);
Log.v(TAG, "SHA1 Hash:" + SHA1hash);
Log.v(TAG, "Correct SHA1:" + correctSHA1);
if (SHA1hash.equals(correctSHA1)) {
Log.v(TAG, "SHA1 hash matched!");
this.abortBroadcast(); //Abort Broadcast for SMS Message
String to = smsMessage[i].getOriginatingAddress ();
SmsManager sm = SmsManager.getDefault();
sm.sendTextMessage (to, null, "success!", null, null);
NotificationManager nm = (NotificationManager) context.getSystemService (Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(android.R.drawable.ic_dialog_info, "Alert", System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity (context, 0, new Intent (context, PhoneFinder.class), 0);
notification.setLatestEventInfo (context, "GPS address", "You have been detected", contentIntent);
nm.notify (R.string.service_start, notification);
//context.startService(new Intent(context, MyService.class));
mp.start();
}
}
}
else if (smsMessage[i].getMessageBody().contains("STOP:")) {
String[] tokens = smsMessage[i].getMessageBody().split(":");
Log.v(TAG, "STOP SMS Message keyword detected");
if (tokens.length >= 2) {
Log.v(TAG, "STOP Token 1: " + tokens[0]);
Log.v(TAG, "STOP Token 2: " + tokens[1]);
String SHA1hash = PhoneFinder.getSHA1(tokens[1]);
Log.v(TAG, "STOP SHA1 Hash:" + SHA1hash);
Log.v(TAG, "STOP Correct SHA1:" + correctSHA1);
if (SHA1hash.equals(correctSHA1)) {
Log.v(TAG, "STOP SHA1 hash matched!");
this.abortBroadcast(); //Abort Broadcast for SMS Message
// context.stopService(new Intent(context, MyService.class));
if (mp.isPlaying())
mp.pause();
}
}
日志错误:
07-22 10:11:30.082: V/Logging Activity(7207): New Broadcast Receiver
07-22 10:11:30.082: V/Logging Activity(7207): Password: passwd
07-22 10:11:30.087: V/MediaPlayer-JNI(7207): native_setup
07-22 10:11:30.087: V/MediaPlayer(7207): constructor
07-22 10:11:30.092: V/MediaPlayer(7207): setListener
07-22 10:11:30.092: V/MediaPlayer-JNI(7207): setDataSourceFD: fd 57
07-22 10:11:30.092: V/MediaPlayer(7207): setDataSource(57, 652, 2625504)
07-22 10:11:30.107: V/MediaPlayer(7207): setVideoSurfaceTexture
07-22 10:11:30.107: V/MediaPlayer(7207): prepare
07-22 10:11:30.112: V/MediaPlayer(7207): message received msg=5, ext1=0, ext2=0
07-22 10:11:30.112: V/MediaPlayer(7207): New video size 0 x 0
07-22 10:11:30.112: V/MediaPlayer(7207): callback application
07-22 10:11:30.117: V/MediaPlayer(7207): back from callback
07-22 10:11:30.117: V/MediaPlayer(7207): message received msg=1, ext1=0, ext2=0
07-22 10:11:30.117: V/MediaPlayer(7207): prepared
07-22 10:11:30.117: V/MediaPlayer(7207): signal application thread
07-22 10:11:30.117: V/MediaPlayer(7207): callback application
07-22 10:11:30.117: V/MediaPlayer(7207): back from callback
07-22 10:11:30.117: V/MediaPlayer(7207): prepare complete - status=0
07-22 10:11:30.122: D/Gsm/SmsMessage(7207): SMS SC timestamp: 1342923088000
07-22 10:11:30.132: V/Logging Activity(7207): RING SMS Message keyword detected
07-22 10:11:30.132: V/Logging Activity(7207): Token 1: RING
07-22 10:11:30.132: V/Logging Activity(7207): Token 2: abc123
07-22 10:11:30.137: V/Logging Activity(7207): SHA1 Hash:6367c48dd193d56ea7b0baad25b19455e529f5ee
07-22 10:11:30.137: V/Logging Activity(7207): Correct SHA1:6367c48dd193d56ea7b0baad25b19455e529f5ee
07-22 10:11:30.137: V/Logging Activity(7207): SHA1 hash matched!
07-22 10:11:30.167: V/MediaPlayer-JNI(7207): start
07-22 10:11:30.167: V/MediaPlayer(7207): start
07-22 10:11:30.202: E/MediaPlayer(7207): mOnVideoSizeChangedListener is null. Failed to send MEDIA_SET_VIDEO_SIZE message.
07-22 10:11:30.202: I/MediaPlayer(7207): Don't send intent. msg.arg1 = 0, msg.arg2 = 0
07-22 10:11:30.202: E/MediaPlayer(7207): mOnPreparedListener is null. Failed to send MEDIA_PREPARED message.
07-22 10:11:37.592: V/Logging Activity(7207): New Broadcast Receiver
07-22 10:11:37.592: V/Logging Activity(7207): Password: passwd
07-22 10:11:37.592: V/MediaPlayer-JNI(7207): native_setup
07-22 10:11:37.592: V/MediaPlayer(7207): constructor
07-22 10:11:37.592: V/MediaPlayer(7207): setListener
07-22 10:11:37.592: V/MediaPlayer-JNI(7207): setDataSourceFD: fd 57
07-22 10:11:37.592: V/MediaPlayer(7207): setDataSource(57, 652, 2625504)
07-22 10:11:37.612: V/MediaPlayer(7207): setVideoSurfaceTexture
07-22 10:11:37.612: V/MediaPlayer(7207): prepare
07-22 10:11:37.617: V/MediaPlayer(7207): message received msg=5, ext1=0, ext2=0
07-22 10:11:37.617: V/MediaPlayer(7207): New video size 0 x 0
07-22 10:11:37.617: V/MediaPlayer(7207): callback application
07-22 10:11:37.617: V/MediaPlayer(7207): back from callback
07-22 10:11:37.617: V/MediaPlayer(7207): message received msg=1, ext1=0, ext2=0
07-22 10:11:37.617: V/MediaPlayer(7207): prepared
07-22 10:11:37.617: V/MediaPlayer(7207): signal application thread
07-22 10:11:37.617: V/MediaPlayer(7207): callback application
07-22 10:11:37.617: V/MediaPlayer(7207): back from callback
07-22 10:11:37.617: V/MediaPlayer(7207): prepare complete - status=0
07-22 10:11:37.617: D/Gsm/SmsMessage(7207): SMS SC timestamp: 1342923096000
07-22 10:11:37.617: V/Logging Activity(7207): STOP SMS Message keyword detected
07-22 10:11:37.617: V/Logging Activity(7207): STOP Token 1: STOP
07-22 10:11:37.617: V/Logging Activity(7207): STOP Token 2: abc123
07-22 10:11:37.617: V/Logging Activity(7207): STOP SHA1 Hash:6367c48dd193d56ea7b0baad25b19455e529f5ee
07-22 10:11:37.617: V/Logging Activity(7207): STOP Correct SHA1:6367c48dd193d56ea7b0baad25b19455e529f5ee
07-22 10:11:37.617: V/Logging Activity(7207): STOP SHA1 hash matched!
07-22 10:11:37.617: V/MediaPlayer(7207): isPlaying: 0
07-22 10:11:37.617: V/MediaPlayer-JNI(7207): isPlaying: 0
07-22 10:11:37.617: E/MediaPlayer(7207): mOnVideoSizeChangedListener is null. Failed to send MEDIA_SET_VIDEO_SIZE message.
07-22 10:11:37.617: I/MediaPlayer(7207): Don't send intent. msg.arg1 = 0, msg.arg2 = 0
07-22 10:11:37.617: E/MediaPlayer(7207): mOnPreparedListener is null. Failed to send MEDIA_PREPARED message.