Hello
I have the source code of an appli that plays .mp4 and i have to make it works with HLS.
The video and the sound are played but i have 2 problems ONLY WITH .m3u8 :
1) When seekTo() is activated (commentaries deleted) the sound is disabled and when i want to quit the player, it makes a long time to do and it makes crash the appli
2) setLooping doesn't work and return Error (-38,0), Attempt to perform seekTo in wrong state: mPlayer=0x1e0380, mCurrentState=0 (below the code)
REMEMBER : THOSE PROBLEMS ARE JUST FOR .M3U8
Here's the code of the player :
Code:
private void playVideo() {
doCleanUp();
try {
// Create a new media player and set the listeners
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(mFilePath);
mMediaPlayer.setDisplay(mSurfaceHolder);
mMediaPlayer.prepare();
mMediaPlayer.start();
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnVideoSizeChangedListener(this);
mMediaPlayer.setOnPreparedListener(this);
//mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
//mMediaPlayer.seekTo(mResumePosition);
//mMediaPlayer.setLooping(true);
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage(), e);
showErrorMessage(mErrorPlayingVideo);
// Toast.makeText(this, "Impossible de jouer la vidéo",
// 5000).show();
}
}
Here's a few of logs when setLooping is activated under setDataSource() :
Code:
error (-38, 0)
prepareAsync called in wrong state 0
prepareAsync_l return error =-38
error: null
java.lang.IllegalStateException
at android.media.MediaPlayer.prepare(Native Method)
at fr.niji.broadpeak.activity.BroadpeakDemoPlayer.playVideo(BroadpeakDemoPlayer.java:409)
at fr.niji.broadpeak.activity.BroadpeakDemoPlayer.onRequestFinished(BroadpeakDemoPlayer.java:585)
at fr.niji.lib.dataproxy.service.DataManager.handleResult(DataManager.java:262)
at fr.niji.lib.dataproxy.service.DataManager.onRequestFinished(DataManager.java:292)
at fr.niji.lib.dataproxy.service.ServiceHelper.handleResult(ServiceHelper.java:297)
at fr.niji.lib.dataproxy.service.ServiceHelper$EvalReceiver.onReceiveResult(ServiceHelper.java:119)
at android.os.ResultReceiver$MyRunnable.run(ResultReceiver.java:43)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4126)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
and below the code :
Code:
Attempt to perform seekTo in wrong state: mPlayer=0x1e0380, mCurrentState=0
error (-38, 0)
Error (-38,0)
Error (-38,0)
Attempt to perform seekTo in wrong state: mPlayer=0x1e0380, mCurrentState=0
Error (-38,0)
Error (-38,0)
Attempt to perform seekTo in wrong state: mPlayer=0x1e0380, mCurrentState=0
thank you for the help !
up
Ok I found the problem.
When you use seekTo() with a .m3u8 file and the value between the parentheses is set to 0, it doesn't work so I added a condition into playBackVideo() method :
Code:
if (mResumePosition > 0)
mMediaPlayer.seekTo(mResumePosition);
So mResumePosition will never be set to 0 and play at the beginning of the file.
Also, i resolved the setLooping() problem, in
Code:
public void onCompletion(final MediaPlayer mediaPlayer)
I added
Code:
mMediaPlayer.release();
playVideo();
and the looping works very well !
A new problem is arrived.
When i click on Resume button, the video goes to the last place when I stopped the player but there is no sound...
If someone has ideas...
Related
Hello,
we are developing something to watch the battery drain - logging battery % steps - and get sometimes an exception into our Uncaught Exception Handler looks like this:
Code:
07-15 12:29:41.815 D/AndroidRuntime(27028): Shutting down VM
07-15 12:29:41.815 W/dalvikvm(27028): threadid=1: thread exiting with uncaught exception (group=0x4001e578)
07-15 12:29:41.815 E/DrainGuardService(27028): Default uncaught exception handler
07-15 12:29:41.815 E/DrainGuardService(27028): Caught throwable java.lang.RuntimeException: [B]Error receiving broadcast Intent [/B]{ act=[B]android.intent.action.BATTERY_CHANGED[/B] flg=0x60000000 (has extras) } in [email protected] for thread Thread[main,5,main]
Thats our Codesnipplet
Code:
private IntentFilter batteryLevelFilterpercentchange = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
private BroadcastReceiver batteryLevelReceiver3;
Code:
batteryLevelReceiver3 = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
int level = -1;
try
{
int rawlevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
if (rawlevel >= 0 && scale > 0) {
level = (rawlevel * 100) / scale;
}
...
We tried to catch the exception with a try-finally but it looks like we are crashing before.
Funny thing: It happens only 1-2 times a week but we want to fix it. How/where can we catch this exception correctly without ending the app?
I also think that its not our mistake, because the system sends the message with the intent. but sometimes it seems not to be filled in correctly.
Thanks in advance!
Here's a pretty cookie cutter BroadcastReceiver that I use frequently(Modified with your code). Let me know if it helps.
Code:
private class BatteryLevelReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent == null)
return;
if (context == null)
return;
String action = intent.getAction();
if (action == null)
return;
if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
int level = -1;
int rawlevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
if (rawlevel >= 0 && scale > 0) {
level = (rawlevel * 100) / scale;
}
else {
// DO SOMETHING ELSE
}
}
}
Thanks, will try tomorrow and report back in a few days after testing.
After optimizing my code - had ~5 batterylevel receiver xD - and implementing your code, everything works like a charm.
Many thanks!
Thanks so much for the code! I was ahving the same issue, now it's solved!!!! Thanks again
Questions or Problems Should Not Be Posted in the Development Forum
Please Post in the Correct Forums & Read the Forum Rules
Moving to Q&A
I would like to query, sms logs (not sms) but the logs that show when you see history of a particular contact. The below code can query the logs however, I cannot delete them as it give me exception.
anyone with a solution or advise on why can't i delete a sms log (showing sent sms, received sms logs).
Code:
public void eraseSmsLogs(Contact contact) {
String phoneNumber = null;
Log.d("pali","phoneService eraseSmsLogs");
Uri smsLogs = Uri.parse("content://logs/sms");
Cursor cursor = context.getContentResolver().query(smsLogs, null, null, null, null);
if(cursor.getCount() > 0) {
cursor.moveToFirst();
for(int i=0; i<cursor.getColumnCount();i++) {
Log.d("pali","phoneService eraseSmsLogs colName i =" + i + " " + cursor.getColumnName(i) + ",colval=" + cursor.getString(i));
}
while(cursor.moveToNext()) {
phoneNumber = cursor.getString(6);
if(matchPhoneNumbers(phoneNumber, contact.getNumber())) {
Log.d("pali","**phoneService eraseSmsLogs no matched**");
//context.getContentResolver().delete(Uri.parse("content://sms"), "_id=?", new String[]{cursor.getString(15)});
context.getContentResolver().delete(smsLogs, "Number=?", new String[]{phoneNumber});
}
}
}
}
and the exception is
Code:
05-14 15:26:47.909: E/AndroidRuntime(26646): FATAL EXCEPTION: main
05-14 15:26:47.909: E/AndroidRuntime(26646): java.lang.UnsupportedOperationException: Cannot delete that URL: content://logs/sms
05-14 15:26:47.909: E/AndroidRuntime(26646): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:146)
05-14 15:26:47.909: E/AndroidRuntime(26646): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114)
05-14 15:26:47.909: E/AndroidRuntime(26646): at android.content.ContentProviderProxy.delete(ContentProviderNative.java:483)
05-14 15:26:47.909: E/AndroidRuntime(26646): at android.content.ContentResolver.delete(ContentResolver.java:692)
if i can query the sms logs, why can't i delete them.
regards,
Hello guys. So i'm trying to make a app that will play a aac stream from an online radio station. I managed to build the project but i get this error when running it.
Code:
05-27 06:12:00.734: E/AndroidRuntime(450): FATAL EXCEPTION: main
05-27 06:12:00.734: E/AndroidRuntime(450): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.spoledge.aacplay/com.spoledge.aacplay.AACPlayerActivity}: java.lang.ClassNotFoundException: com.spoledge.aacplay.AACPlayerActivity in loader dalvik.system.PathClassLoader[/data/app/com.spoledge.aacplay-2.apk]
05-27 06:12:00.734: E/AndroidRuntime(450): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
05-27 06:12:00.734: E/AndroidRuntime(450): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
05-27 06:12:00.734: E/AndroidRuntime(450): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-27 06:12:00.734: E/AndroidRuntime(450): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
05-27 06:12:00.734: E/AndroidRuntime(450): at android.os.Handler.dispatchMessage(Handler.java:99)
05-27 06:12:00.734: E/AndroidRuntime(450): at android.os.Looper.loop(Looper.java:123)
05-27 06:12:00.734: E/AndroidRuntime(450): at android.app.ActivityThread.main(ActivityThread.java:3683)
05-27 06:12:00.734: E/AndroidRuntime(450): at java.lang.reflect.Method.invokeNative(Native Method)
05-27 06:12:00.734: E/AndroidRuntime(450): at java.lang.reflect.Method.invoke(Method.java:507)
05-27 06:12:00.734: E/AndroidRuntime(450): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-27 06:12:00.734: E/AndroidRuntime(450): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-27 06:12:00.734: E/AndroidRuntime(450): at dalvik.system.NativeStart.main(Native Method)
05-27 06:12:00.734: E/AndroidRuntime(450): Caused by: java.lang.ClassNotFoundException: com.spoledge.aacplay.AACPlayerActivity in loader dalvik.system.PathClassLoader[/data/app/com.spoledge.aacplay-2.apk]
05-27 06:12:00.734: E/AndroidRuntime(450): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
05-27 06:12:00.734: E/AndroidRuntime(450): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
05-27 06:12:00.734: E/AndroidRuntime(450): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
05-27 06:12:00.734: E/AndroidRuntime(450): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
05-27 06:12:00.734: E/AndroidRuntime(450): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
05-27 06:12:00.734: E/AndroidRuntime(450): ... 11 more
This is my project AACPlayerActivity.java code:
Code:
package com.spoledge.aacplay;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.spoledge.aacdecoder.AACPlayer;
import com.spoledge.aacdecoder.PlayerCallback;
/**
* This is the main activity.
*/
public class AACPlayerActivity extends Activity implements View.OnClickListener, PlayerCallback {
private History history;
private AutoCompleteTextView urlView;
private Button btnPlay;
private Button btnStop;
private TextView txtStatus;
private EditText txtBufAudio;
private EditText txtBufDecode;
private ProgressBar progress;
private Handler uiHandler;
private AACPlayer aacPlayer;
////////////////////////////////////////////////////////////////////////////
// PlayerCallback
////////////////////////////////////////////////////////////////////////////
private boolean playerStarted;
public void playerStarted() {
uiHandler.post( new Runnable() {
public void run() {
txtBufAudio.setEnabled( false );
txtBufDecode.setEnabled( false );
btnPlay.setEnabled( false );
btnStop.setEnabled( true );
txtStatus.setText( R.string.text_buffering );
progress.setProgress( 0 );
progress.setVisibility( View.VISIBLE );
playerStarted = true;
}
});
}
/**
* This method is called periodically by PCMFeed.
*
* @param isPlaying false means that the PCM data are being buffered,
* but the audio is not playing yet
*
* @param audioBufferSizeMs the buffered audio data expressed in milliseconds of playing
* @param audioBufferCapacityMs the total capacity of audio buffer expressed in milliseconds of playing
*/
public void playerPCMFeedBuffer( final boolean isPlaying,
final int audioBufferSizeMs, final int audioBufferCapacityMs ) {
uiHandler.post( new Runnable() {
public void run() {
progress.setProgress( audioBufferSizeMs * progress.getMax() / audioBufferCapacityMs );
if (isPlaying) txtStatus.setText( R.string.text_playing );
}
});
}
public void playerStopped( final int perf ) {
uiHandler.post( new Runnable() {
public void run() {
btnPlay.setEnabled( true );
btnStop.setEnabled( false );
txtBufAudio.setEnabled( true );
txtBufDecode.setEnabled( true );
// txtStatus.setText( R.string.text_stopped );
txtStatus.setText( "" + perf + " %" );
progress.setVisibility( View.INVISIBLE );
playerStarted = false;
}
});
}
public void playerException( final Throwable t) {
uiHandler.post( new Runnable() {
public void run() {
new AlertDialog.Builder( AACPlayerActivity.this )
.setTitle( R.string.text_exception )
.setMessage( t.toString())
.setNeutralButton( R.string.button_close,
new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dialog, int id) {
dialog.cancel();
}
}
)
.show();
txtStatus.setText( R.string.text_stopped );
if (playerStarted) playerStopped( 0 );
}
});
}
////////////////////////////////////////////////////////////////////////////
// OnClickListener
////////////////////////////////////////////////////////////////////////////
/**
* Called when a view has been clicked.
*/
public void onClick( View v ) {
try {
switch (v.getId()) {
case R.id.view_main_button_play: start(); break;
case R.id.view_main_button_stop: stop(); break;
}
}
catch (Exception e) {
Log.e( "AACPlayerActivity", "exc" , e );
}
}
////////////////////////////////////////////////////////////////////////////
// Protected
////////////////////////////////////////////////////////////////////////////
@Override
protected void onCreate( Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
setContentView( R.layout.main );
btnPlay = (Button) findViewById( R.id.view_main_button_play );
btnStop = (Button) findViewById( R.id.view_main_button_stop );
urlView = (AutoCompleteTextView) findViewById( R.id.view_main_edit_url );
txtStatus = (TextView) findViewById( R.id.view_main_text_status );
txtBufAudio = (EditText) findViewById( R.id.view_main_text_bufaudio );
txtBufDecode = (EditText) findViewById( R.id.view_main_text_bufdecode );
progress = (ProgressBar) findViewById( R.id.view_main_progress );
txtBufAudio.setText( String.valueOf( AACPlayer.DEFAULT_AUDIO_BUFFER_CAPACITY_MS ));
txtBufDecode.setText( String.valueOf( AACPlayer.DEFAULT_DECODE_BUFFER_CAPACITY_MS ));
btnPlay.setOnClickListener( this );
btnStop.setOnClickListener( this );
history = new History( this );
history.read();
if (history.size() == 0 ) {
history.addUrl( "/sdcard/local/cro2-32.aac" );
history.addUrl( "netshow.play.cz:8000/crocb32aac" );
history.addUrl( "62.44.1.26:8000/cro2-128aac" );
history.addUrl( "2483.live.streamtheworld.com:80/KFTZFMAACCMP3" );
history.addUrl( "yourmuze.com:8000/play/paradise/l.aac" );
history.addUrl( "yourmuze.com:8000/play/paradise/m.aac" );
history.addUrl( "yourmuze.com:8000/play/paradise/h.aac" );
}
urlView.setAdapter( history.getArrayAdapter());
uiHandler = new Handler();
}
@Override
protected void onPause() {
super.onPause();
history.write();
}
@Override
protected void onDestroy() {
super.onDestroy();
stop();
}
////////////////////////////////////////////////////////////////////////////
// Private
////////////////////////////////////////////////////////////////////////////
private void start() {
stop();
aacPlayer = new AACPlayer( this, getInt( txtBufAudio ), getInt( txtBufDecode ));
aacPlayer.playAsync( getUrl());
}
private void stop() {
if (aacPlayer != null) {
aacPlayer.stop();
aacPlayer = null;
}
}
private String getUrl() {
String ret = urlView.getText().toString();
history.addUrl( ret );
return ret;
}
private int getInt( EditText et ) {
return Integer.parseInt( et.getText().toString());
}
}
And this is my AndroidManifest.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="schemas.android.com/apk/res/android"
package="com.spoledge.aacplay"
android:versionCode="1"
android:versionName="@string/app_version"
>
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk android:minSdkVersion="10"/>
<application
android:label="@string/app_name"
android:debuggable="true"
>
<activity
android:name="com.spoledge.aacplay.AACPlayerActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
So can someone help me solve this out? Thanks!
Questions or Problems Should Not Be Posted in the Development Forum
Please Post in the Correct Forums & Read the Forum Rules
Moving to Q&A
Here is your problem:
05-27 06:12:00.734: E/AndroidRuntime(450): Caused by: java.lang.ClassNotFoundException: com.spoledge.aacplay.AACPlayerActivity in loader dalvik.system.PathClassLoader[/data/app/com.spoledge.aacplay-2.apk]
Click to expand...
Click to collapse
are you using any external libraries?
are they exactly in libs directory in your project?
so i am developing an app to go with my home made alarm system...i am using the jy-mcu bluetooth module for arduino...it is running at 56700 baud...but when i try to transmit a string, either it gets chopped up or it is missing parts...can someone give my code a once over and tell me if it is anything on the Android side of things??? i basically moded the Bluetooth Chat sample in the api 8 folder...so i know it worked once before.
Here is some of the data from the logcat:
11-20 01:35:53.754: I/GET MESSAGE(16751): why di
11-20 01:35:53.764: I/GET MESSAGE(16751): d i never know streetlight manifesto covered a postal service son
11-20 01:46:10.436: I/GET MESSAGE(16751): w
11-20 01:46:10.446: I/GET MESSAGE(16751): hy did i never know streetlight manifesto covered a postal service son
11-20 01:46:15.551: I/GET MESSAGE(16751): w
11-20 01:46:15.581: I/GET MESSAGE(16751): ce sonii never know streetlight manifesto covered a posta
11-20 01:46:15.591: I/GET MESSAGE(16751): ce soni
11-20 01:46:15.591: I/GET MESSAGE(16751): ce son
11-20 01:46:22.558: I/GET MESSAGE(16751): w
11-20 01:46:22.568: I/GET MESSAGE(16751): hy did i never know streetlight manifesto covered a postal service son
the sentence was supposed to be "why did i never know streetlight manifesto covered a postal service son"
any idea
ps code is include via zip/rar
I figured out where it is erroring out
I have figured out where i am having the issues...it is on the ConnectedThread...here is the code:
Code:
public void run()
{
Log.i(TAG, "BEGIN mConnectedThread");
byte[] buffer = new byte[1024];
int bytes;
String mm = "";
while (true)
{
try
{
bytes = mmInStream.read(buffer);
mm += new String(buffer,0,bytes);
if (mm.contains("%"))
{
String[] temp = mm.split("%");
mHandler.obtainMessage(Main.MESSAGE_READ, bytes, -1, temp[0])
.sendToTarget();
if (temp.length > 1)
{
mm = "";
for(int i = 1; i < temp.length - 1; i++)
{
mm += temp[i];
if(i + 1 < mm.length() - 1)
{
mm += "+";
}
else
{
}
}
}
}
}
catch (IOException e)
{
Log.e(TAG, "disconnected", e);
connectionLost();
break;
}
catch (Exception e)
{
Log.e(TAG, "ERROR-RUN", e);
}
}
}
So here is what it is SUPPOSED to do...it is supposed to read in the data from the BlueTooth being sent from my Arduino...the commands are delimited by a +...let say it sends the string "update-1-2-2-1-2-1-1-1-2-2-1-2+"...it will split the string at the +...send the most recent command to the handler...lets say it is being slow and receives 2 commands "update-1-2-2-1-2-1-1-1-2-2-1-2+update-1-2-2-1-2-1-1-1-2-2-1-2+"...still not a problem...but lets say it hits the end of the buffer half way thur like "update-1-2-2-1-2-1-1-1-2-2-1-2+update-1-2-"...it is supposed to save the 2nd part and wait for the remainder...but it isn't saving it...when i use debug mode...it for some reason starts to get to the for loop and then just ends up back at the beginning of the while...truth be told i am NOT good at Java...i am a VB programmer at heart (be my guest to point fingers...lol)...does anyone see any issues with the code???
Hello,
I use AppWidgetProvider on Android, this bindService Foreground widget and then when it calls Messenger I get this error (works fine if it is Activity), mMessengerService is null in sendMess method:
Java:
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
// This is called when the connection with the service has
// been established, giving us the service object we can use
// to interact with the service. Because we have bound to a
// explicit service that we know is running in our own
// process, we can cast its IBinder to a concrete class and
// directly access it.
//mBoundService = ((MCBluetooth.LocalBinder)service).getService();
mMessengerService = new Messenger(service);
//mMessengerService=((MCBluetooth.LocalBinder)service).getMessenger();
Log.v(TAG,"onServiceConnected");
// Tell the user about this for our demo.
Toast.makeText(mContextWidget,
TAG+" service MCBluetoothForeground connected",
Toast.LENGTH_SHORT).show();
}
public void onServiceDisconnected(ComponentName className) {
// This is called when the connection with the service has
// been unexpectedly disconnected -- that is, its process
// crashed. Because it is running in our same process, we
// should never see this happen.
// mBoundService = null;
mMessengerService=null;
Toast.makeText(mContextWidget.getApplicationContext(),TAG+" service MCBluetoothForeground disconnected",Toast.LENGTH_SHORT).show();
}
};
void doBindServiceForeGround() {
// Establish a connection with the service. We use an explicit
// class name because we want a specific service implementation
// that we know will be running in our own process (and thus
// won't be supporting component replacement by other
// applications).
Intent intent=new Intent(mContextWidget, MCBluetoothForeGround.class);
mContextWidget.getApplicationContext().bindService(intent,
mConnection,Context.BIND_AUTO_CREATE);
mIsBound = true;
}
void doUnbindService() {
if (mIsBound) {
// Detach our existing connection.
mContextWidget.getApplicationContext().unbindService(mConnection);
mIsBound = false;
}
}
private void sendMess(){
try {
Message message=new Message();
message.what=10;
if(mMessengerService==null){
Log.v(TAG,"mMessengerService is null");
}
mMessengerService.send(message);
} catch (RemoteException e) {
e.printStackTrace();
}
}
Code:
2021-05-18 21:21:24.043 11598-11598/fr.jm.managercamera E/AndroidRuntime: FATAL EXCEPTION: main
Process: fr.jm.managercamera, PID: 11598
java.lang.RuntimeException: Unable to start receiver fr.jm.managercamera.MainActivityWidget: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.os.Messenger.send(android.os.Message)' on a null object reference
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3264)
at android.app.ActivityThread.-wrap17(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1682)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:251)
at android.app.ActivityThread.main(ActivityThread.java:6572)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.os.Messenger.send(android.os.Message)' on a null object reference
at fr.jm.managercamera.MainActivityWidget.sendCommand(MainActivityWidget.java:534)
at fr.jm.managercamera.MainActivityWidget.processVideo(MainActivityWidget.java:487)
at fr.jm.managercamera.MainActivityWidget.onReceive(MainActivityWidget.java:286)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3257)
at android.app.ActivityThread.-wrap17(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1682)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:251)
at android.app.ActivityThread.main(ActivityThread.java:6572)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Why?
Thank you.