Infinite sound playing loop - how to stop?

All your problems with Audio, Video and Images.

Infinite sound playing loop - how to stop?

Postby Mcingwe » Tue Jan 26, 2010 3:52 pm

(did not find any similar topic, sorry if a repeat)

I was testing SoundPool methods on HTC Hero device and fired a sound to play in an infinite loop. After I quit the app, it still plays.
I did not save any streamId, and any calls to soundPool.stop() fail -- sound still plays. Anyway the soundPool object is new each time I start the app -- so it would not stop any stream even if I knew streamId.

Is there a way to stop the sound from the program somehow, like may be there's a method like stopAll in AudioManager or anything?

Rebooting the phone is not an option.

Many thanks.
Mcingwe
Freshman
Freshman
 
Posts: 3
Joined: Tue Jan 26, 2010 3:41 pm

Top

Postby Draffodx » Tue Jan 26, 2010 4:29 pm

have you tried running it in a thread and using a boolean vaule to gracefully stop the thread?
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Postby Mcingwe » Tue Jan 26, 2010 4:38 pm

Draffodx wrote:have you tried running it in a thread and using a boolean vaule to gracefully stop the thread?


well, I've already left that application, and every time I start it again I believe it creates all the new objects, except, perhaps, for AudioManager.

do you mean I can now amend an app to make it threaded and stop that orphan thread? would not this new copy be another app having nothing with my infinite stream?

if not, could you please point me to a further reading on this?

thanks.
Mcingwe
Freshman
Freshman
 
Posts: 3
Joined: Tue Jan 26, 2010 3:41 pm

Postby Draffodx » Tue Jan 26, 2010 5:29 pm

I had similiar problems with recording and playing back using the AudioRecord and AudioTrack classes.

The sound kept playing after I exited the application so I ran it in its own thread and used a boolean value so that the thread onlu ran when that value was true.

This works for me but I am not familiar with sound pool to know if it will work with it.

Here is how I done my implementation

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class Record extends Thread
  2.  
  3.       {
  4.  
  5.            
  6.  
  7.  
  8.  
  9.               static final int bufferSize = 200000;
  10.  
  11.               final short[] buffer = new short[bufferSize];
  12.  
  13.               short[] readBuffer = new short[bufferSize];
  14.  
  15.  
  16.  
  17.               public void run() {  
  18.  
  19.                 isRecording = true;
  20.  
  21.                 android.os.Process.setThreadPriority
  22.  
  23.                 (android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
  24.  
  25.  
  26.  
  27.                 int buffersize = AudioRecord.getMinBufferSize(11025,
  28.  
  29.                 AudioFormat.CHANNEL_CONFIGURATION_MONO,
  30.  
  31.                 AudioFormat.ENCODING_PCM_16BIT);
  32.  
  33.  
  34.  
  35.                                arec = new AudioRecord(MediaRecorder.AudioSource.MIC,
  36.  
  37.                                                11025,
  38.  
  39.                                                AudioFormat.CHANNEL_CONFIGURATION_MONO,
  40.  
  41.                                                AudioFormat.ENCODING_PCM_16BIT,
  42.  
  43.                                                buffersize);
  44.  
  45.  
  46.  
  47.                                atrack = new AudioTrack(AudioManager.STREAM_VOICE_CALL,
  48.  
  49.                                                11025,
  50.  
  51.                                                AudioFormat.CHANNEL_CONFIGURATION_MONO,
  52.  
  53.                                                AudioFormat.ENCODING_PCM_16BIT,
  54.  
  55.                                                buffersize,
  56.  
  57.                                                AudioTrack.MODE_STREAM);
  58.  
  59.                              
  60.  
  61.                            
  62.  
  63.                                atrack.setPlaybackRate(11025);
  64.  
  65.  
  66.  
  67.                                byte[] buffer = new byte[buffersize];
  68.  
  69.                                arec.startRecording();
  70.  
  71.                                atrack.play();
  72.  
  73.  
  74.  
  75.                                while(isRecording) {
  76.  
  77.                                        arec.read(buffer, 0, buffersize);
  78.  
  79.                                        atrack.write(buffer, 0, buffer.length);
  80.  
  81.                                }
  82.  
  83.  
  84.  
  85.                                
  86.  
  87.               }
  88.  
  89.       }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Postby Mcingwe » Tue Jan 26, 2010 5:38 pm

cool, many thanks ))

rebooting the phone now anyway.

but how did you manage to stop that sound in that case you exited and sound was still on? just rebooted? or you launched an updated app and it stopped?
Mcingwe
Freshman
Freshman
 
Posts: 3
Joined: Tue Jan 26, 2010 3:41 pm

Postby Draffodx » Wed Jan 27, 2010 10:12 am

Mcingwe wrote:cool, many thanks ))

rebooting the phone now anyway.

but how did you manage to stop that sound in that case you exited and sound was still on? just rebooted? or you launched an updated app and it stopped?


I have a stop button that changes the boolean isRecording to false so that the thread stops, this stops the thread however the VOICE_CALL_STREAM remains open on the phone and you can hear static, so I had to mute the Stream as well on the button pressed event
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Top

Postby shishir.bobby » Sat Feb 27, 2010 10:39 am

hi, just watching ur thread,
my problem is almost same as urs.


in my condition, i hv two activities

one contain few button(u can say button1 , button 2, button 3 etc)

and second activity plays the media, when i hit play button there, acoording to the button click,
if i click on button1, song1 starts, button 2 plays song2 like dis,
my 2nd activity also contains 1 back button,

now the problem is,

when i hit button1, song1 gets start playing....so far its fine

now when i hit back button, song stops and i got activity 1...
so far its fine


now, second contion....
when i hit button1, moves to activty 2 and not hit play button,(means not start playing song), and hits the back button, my application gets crashed.

its difficult to explain my problem in words,but hope u all get it....


let me knw if u guys knw a better way to accomplish my things



regards
Shishir.bobby
shishir.bobby
Experienced Developer
Experienced Developer
 
Posts: 76
Joined: Thu Apr 09, 2009 11:41 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 26 guests