6 Replies - 1235 Views - Last Post: 02 May 2012 - 11:53 AM

#1 oha055  Icon User is offline

  • D.I.C Regular

Reputation: 49
  • View blog
  • Posts: 270
  • Joined: 02-February 09

bad sound quality

Posted 02 May 2012 - 10:25 AM

Hi!

My button is playing a sound from within a SoundPool (http://developer.and.../SoundPool.html) when it is clicked, like this:

	public void onclick(View v) {

		// Get the users sound settings
		AudioManager audioManager = (AudioManager)getSystemService(AUDIO_SERVICE);
		float actualVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
		float maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
		float volume = actualVolume / maxVolume;

		// Are all sounds loaded?
		if(soundsLoaded) {
			soundPool.play(soundList.get(0), volume, volume, 1, 0, 1f);
		} else {
			Toast.makeText(this, "Please wait for all the sounds to load.", Toast.LENGTH_SHORT);
		}
	}



My problem is that the sound that's playing (about half a second long) is really choppy. I have tried different compressed formats(ogg, flac, mp3) as well as wav, but they all sound really bad. What am I doing wrong? Help is greattly appreciated! :)

This post has been edited by oha055: 02 May 2012 - 11:50 AM


Is This A Good Question/Topic? 0
  • +

Replies To: bad sound quality

#2 H3R3T1C  Icon User is offline

  • Android Expert
  • member icon

Reputation: 277
  • View blog
  • Posts: 757
  • Joined: 30-March 07

Re: bad sound quality

Posted 02 May 2012 - 10:34 AM

cecknuot this tutorial http://www.vogella.c...ia/article.html

This post has been edited by H3R3T1C: 02 May 2012 - 10:34 AM

Was This Post Helpful? 0
  • +
  • -

#3 oha055  Icon User is offline

  • D.I.C Regular

Reputation: 49
  • View blog
  • Posts: 270
  • Joined: 02-February 09

Re: bad sound quality

Posted 02 May 2012 - 10:43 AM

Yes, that code is identical to mine. Now what?
Was This Post Helpful? 0
  • +
  • -

#4 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: bad sound quality

Posted 02 May 2012 - 11:09 AM

You need to post more of your code.
Was This Post Helpful? 0
  • +
  • -

#5 H3R3T1C  Icon User is offline

  • Android Expert
  • member icon

Reputation: 277
  • View blog
  • Posts: 757
  • Joined: 30-March 07

Re: bad sound quality

Posted 02 May 2012 - 11:19 AM

Try using media player http://developer.and...ediaplayer.html

Sent using my Evo 4G
Was This Post Helpful? 0
  • +
  • -

#6 oha055  Icon User is offline

  • D.I.C Regular

Reputation: 49
  • View blog
  • Posts: 270
  • Joined: 02-February 09

Re: bad sound quality

Posted 02 May 2012 - 11:49 AM

View PostH3R3T1C, on 02 May 2012 - 08:19 PM, said:

Try using media player http://developer.and...ediaplayer.html

Sent using my Evo 4G


Hmm... I have also been looking at MediaPlayer, but I read that SoundPool is preferable for short sound effects.

View PostEndLessMind, on 02 May 2012 - 08:09 PM, said:

You need to post more of your code.


Inside onCreate():

		soundsLoaded = false;
		soundBtnList = new ArrayList<Button>();
		soundList = new ArrayList<Integer>();
		toneSpinner = (Spinner)findViewById(R.id.tone_spinner);
		soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
		soundPool.setonloadCompleteListener(new onloadCompleteListener() {
			public void onloadComplete(SoundPool soundPool, int sampleId, int status) {
				soundsLoaded = true;
			}
		});
		int soundID = soundPool.load(this, R.raw.s1t1, 1);
		soundList.add(soundID);


Was This Post Helpful? 0
  • +
  • -

#7 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: bad sound quality

Posted 02 May 2012 - 11:53 AM

Mediaplayer i really simple
MediaPlayer mp = new MediaPlayer();
String s = "a url or uri to a song"
mp.setOnPreparedListener(new OnPreparedListener() {

	public void onPrepared(MediaPlayer arg0) {
		// TODO Auto-generated method stub
		mp.start();

	}});
mp.setDataSource(s);
mp.prepare();


That will start buffering a song, and start playing when it has buffered enough :)

This post has been edited by EndLessMind: 02 May 2012 - 11:54 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1