Click here to Skip to main content
15,849,721 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The main problem is that same code (using builtin MediaPlayer class) works on other devices, but wan't work on many HTCs and Galaxys. Without any exceptions - just silence.
According to playmarket's comments and my tests, there is no sound at least on:
HTC Desire V
Galaxy s2
Galaxy s3
Galaxy s4

Please help.
Posted
Updated 28-Feb-14 12:01pm
v3

After a long time I solved it by using SoundPool instead MediaPlayer class. I don't know why MediaPlayer doesn't worked for HTCs and Galaxys during my tests. But need remember the next:
- Must to wait after this method or call all loadings in onCreate:
Java
soundPool.load(context, R.raw.sound, 1);

before playing sounds. - Yes, I know that there is an onCompleteLoading event, but is also doesn't worked in my case. Thanks to all. Problem solved and maybe would be helpfull for someone else...
 
Share this answer
 
v2
We had the same issue in one of our project, removing setAudioStreamType solved it, however we only needed to play small mp3 files.

here is the code from the project

Java
public class AsyncCdnAccess extends AsyncTask<Configuration,boolean[],boolean[]>{
        
        private MediaPlayer player;

        @Override
        protected boolean[] doInBackground(Configuration... args){
                boolean[] result=new boolean[args.length];
                for(int i=0;i<args.length;i++){
                       //...some other code
                       result[i]=feedback&& playRemote(args[].word);
                }
        }

	public void setupPlayer() {

		 this.player = new MediaPlayer();
		this.player.setVolume(1.0F, 1.0F);

		this.player.setOnCompletionListener(new OnCompletionListener() {
 			@Override
			public void onCompletion(MediaPlayer arg0) {
				//removed (project specific codes)

				stop();
			  }
		 });
	}

	 public boolean playRemote(String word) {

		stop();

		synchronized (this) {

			setupPlayer();

			// player.setAudioStreamType(AudioManager.STREAM_MUSIC);

			String path = getRequestRemote(this.currentCdn, word);

			//removed (project specific codes)

			this.player.setDataSource(path);
			this.player.prepare();
			this.player.start();

                        isPlaying = true;

			return true;
		}
	}

	public void stop() {

		if (!isPlaying)
			return;

		synchronized (this) {
			this.player.stop();
			//this.player.reset();
			this.player.release();

			isPlaying = false;
	}
     }
}


we tested the application with these Samsung devices

Galaxy S
Galaxy S3
Galaxy S4
Galaxy Note
Galaxy Note2

Galaxy Tab
Galaxy Tab 2 7.0
Galaxy Tab 2 10.1

hope this helps
 
Share this answer
 
v3
Comments
MegaSinner 2-Mar-14 6:52am    
Thanks. Tried your solution, but not helped, same silence :( Why you are using "this" before 'player' and where its declared?
Hessam Jalali 2-Mar-14 7:34am    
Sorry it didn't help, thats odd, maybe the problem is with content and codecs, did you tried other formats?

provided code is part of our audio playback class, the 'player' is defined as a private variable in the class, which extends AsyncTask and the 'playRemote' method posted in the solution is called in 'doInBackground' method (updated the solution)
MegaSinner 2-Mar-14 13:42pm    
Tried with MP3 and OGG-format also. I thought MP3 is a standart for all devices...
There might be an issue with the format of the file.
For example, some of the devices support the .wma files (Windows Media Audio format) but the Galaxy doesn't so unless you find a way to convert that kind of stream to playable stream.

See the very similar thread here[^].

-KR
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900