如何在HTC或Galaxy上播放声音? [英] How to play sound on HTC or Galaxy?

查看:69
本文介绍了如何在HTC或Galaxy上播放声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

主要问题是相同的代码(使用内置的MediaPlayer类)可以在其他设备上运行,但不适用于许多HTC和Galaxys。没有任何例外 - 只是沉默。

根据playmarket的评论和我的测试,至少没有声音:

HTC Desire V

Galaxy s2

Galaxy s3

Galaxy s4



请帮忙。

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.

推荐答案

很长一段时间后,我使用 SoundPool 而不是 MediaPlayer 类来解决它。我不知道为什么 MediaPlayer 在我的测试中不适用于 HTC Galaxys 。但需要记住下一个:

- 必须等待此方法或调用 onCreate 中的所有加载:

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:
soundPool.load(context, R.raw.sound, 1);



播放声音之前。 - 是的,我知道有一个 onCompleteLoading 事件,但在我的情况下也没有用。谢谢大家。问题解决了,也许对其他人有帮助......


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...


我们在其中一个项目中遇到了同样的问题,删除 setAudioStreamType 解决了它,但是我们只需要播放小的mp3文件。



这里是项目代码



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

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;
	}
     }
}





我们用这些三星设备测试了应用程序



Galaxy S

Galaxy S3

Galaxy S4

Galaxy Note

Galaxy Note2



Galaxy Tab

Galaxy Tab 2 7.0

Galaxy Tab 2 10.1



希望这有帮助



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


文件的格式可能存在问题。

例如,有些设备支持.wma文件(Windows Media Audio格式),但 Galaxy不支持,除非你找到一种方法来转换那种流到可播放的流。



查看非常相似的主题这里 [ ^ ]。



-KR
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


这篇关于如何在HTC或Galaxy上播放声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆