Working_Hard
Lurker
I am trying to create a thread program which will keep on playing two sound in 1 second interval. When back button is pressed the app will close and the sounds will stop.
Initially when I was pressing back button the app was closing but the sound did not stop hence overridden the method onBackPressed and put thread.terminate method in onBackPressed method. That caused sound to stop but after app was closed error message is popping up. Screenshot of the error is given elow
Below is the code. I have placed try-catch and Log.v in every position but no error received in the log. But found below error, not sure from where this error is coming as this is not associated to any log tag. Below is the error details
onFatalError, processing error from engine(4)
com.google.android.apps.gsa.shared.speech.b.g: Error reading from input stream
at com.google.android.apps.gsa.staticplugins.recognizer.j.a.a(SourceFile:28)
at com.google.android.apps.gsa.staticplugins.recognizer.j.b.run(SourceFile:15)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at com.google.android.apps.gsa.shared.util.concurrent.a.ag.run(Unknown Source:4)
at com.google.android.apps.gsa.shared.util.concurrent.a.bo.run(SourceFile:4)
at com.google.android.apps.gsa.shared.util.concurrent.a.bo.run(SourceFile:4)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
at com.google.android.apps.gsa.shared.util.concurrent.a.ak.run(SourceFile:6)
Caused by: com.google.android.apps.gsa.shared.exception.GsaIOException: Error code: 393238 | Buffer overflow, no available space.
at com.google.android.apps.gsa.speech.audio.Tee.f(SourceFile:103)
at com.google.android.apps.gsa.speech.audio.au.read(SourceFile:2)
at java.io.InputStream.read(InputStream.java:101)
at com.google.android.apps.gsa.speech.audio.ao.run(SourceFile:18)
at com.google.android.apps.gsa.speech.audio.an.run(SourceFile:2)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at com.google.android.apps.gsa.shared.util.concurrent.a.ag.run(Unknown Source:4)
at com.google.android.apps.gsa.shared.util.concurrent.a.bo.run(SourceFile:4)
at com.google.android.apps.gsa.shared.util.concurrent.a.bo.run(SourceFile:4)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
at com.google.android.apps.gsa.shared.util.concurrent.a.ak.run(SourceFile:6)
Code is shown below....
Initially when I was pressing back button the app was closing but the sound did not stop hence overridden the method onBackPressed and put thread.terminate method in onBackPressed method. That caused sound to stop but after app was closed error message is popping up. Screenshot of the error is given elow
Below is the code. I have placed try-catch and Log.v in every position but no error received in the log. But found below error, not sure from where this error is coming as this is not associated to any log tag. Below is the error details
onFatalError, processing error from engine(4)
com.google.android.apps.gsa.shared.speech.b.g: Error reading from input stream
at com.google.android.apps.gsa.staticplugins.recognizer.j.a.a(SourceFile:28)
at com.google.android.apps.gsa.staticplugins.recognizer.j.b.run(SourceFile:15)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at com.google.android.apps.gsa.shared.util.concurrent.a.ag.run(Unknown Source:4)
at com.google.android.apps.gsa.shared.util.concurrent.a.bo.run(SourceFile:4)
at com.google.android.apps.gsa.shared.util.concurrent.a.bo.run(SourceFile:4)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
at com.google.android.apps.gsa.shared.util.concurrent.a.ak.run(SourceFile:6)
Caused by: com.google.android.apps.gsa.shared.exception.GsaIOException: Error code: 393238 | Buffer overflow, no available space.
at com.google.android.apps.gsa.speech.audio.Tee.f(SourceFile:103)
at com.google.android.apps.gsa.speech.audio.au.read(SourceFile:2)
at java.io.InputStream.read(InputStream.java:101)
at com.google.android.apps.gsa.speech.audio.ao.run(SourceFile:18)
at com.google.android.apps.gsa.speech.audio.an.run(SourceFile:2)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at com.google.android.apps.gsa.shared.util.concurrent.a.ag.run(Unknown Source:4)
at com.google.android.apps.gsa.shared.util.concurrent.a.bo.run(SourceFile:4)
at com.google.android.apps.gsa.shared.util.concurrent.a.bo.run(SourceFile:4)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
at com.google.android.apps.gsa.shared.util.concurrent.a.ak.run(SourceFile:6)
Code is shown below....
Java:
public class MainActivity extends AppCompatActivity {
MediaPlayer mp;
MediaPlayer mq;
Task tsk;
Thread myThread;
TextView txt;
int iTest,iTerminate;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iTest = 0;
iTerminate = 1;
txt = (TextView)findViewById(R.id.txtVwTest);
mp = MediaPlayer.create(this, R.raw.sound_1);
mq = MediaPlayer.create(this, R.raw.sound_2);
tsk= new Task();
myThread=new Thread(tsk);
myThread.setDaemon(false);
myThread.start();
}
@Override
protected void onPause() {
super.onPause();
if (myThread!=null)
{
try {
iTerminate = 0;
myThread.interrupt();
myThread = null;
}
catch (Exception ex) {
Log.v("ThreadStopLog",ex.getMessage());
}
}
}
@Override
public void onBackPressed() {
if (myThread!=null)
{
try {
iTerminate = 0;
myThread.interrupt();
//myThread.stop();
myThread = null;
}
catch (Exception ex) {
Log.v("ThreadStopLog",ex.getMessage());
}
}
super.onBackPressed();
}
@Override
protected void onStop() {
if (myThread!=null)
{
try {
iTerminate = 0;
myThread.interrupt();
myThread = null;
}
catch (Exception ex) {
Log.v("ThreadStopLog",ex.getMessage());
}
}
super.onStop();
}
@Override
protected void onDestroy() {
if (myThread!=null)
{
try {
iTerminate = 0;
myThread.interrupt();
myThread = null;
}
catch (Exception ex) {
Log.v("ThreadStopLog",ex.getMessage());
}
}
super.onDestroy();
}
class Task implements Runnable {
@Override
public void run() {
if (Thread.interrupted()==true)
{
iTerminate = 0;
return;
}
while (iTerminate == 1) {
iTest++;
//txt.setText(iTest);
Log.v("ThreadTest",Integer.toString(iTest));
try {
mp.start();
}
catch (Exception ex)
{
Log.v("SoundError --> mp",ex.getMessage().toString());
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Log.v("SleepError --> mp-sleep",e.getMessage().toString());
}
try {
//mp.stop();
mq.start();
}
catch (Exception ex)
{
Log.v("SoundError --> mq",ex.getMessage().toString());
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Log.v("SleepError --> mq-sleep",e.getMessage().toString());
}
try {
mq.stop();
}
catch (Exception ex)
{
Log.v("SoundError --> mq-stop",ex.getMessage().toString());
}
}
}
}
}