Android 应用程序上循环音频的问题
由于登录混乱,我重复这个问题。如果任何版主看到此内容,我希望将其保留为最新状态,因为我无法再访问以前的登录信息。
我遇到了一些问题。我正在尝试在我的 Android 应用程序中连续循环播放声音。
使用 MediaPlayer:MP3 播放正常,但末尾有一个文件中不存在的间隙。我读到它与解码器有关,并且 ogg 应该可以工作。尝试使用ogg,但仍然得到间隙,这绝对不在文件中。
使用 SoundPool 类和 ogg(使用这个家伙有趣的类:http ://www.droidnova.com/creating-sound-effects-in-android-part-1,570.html),
声音开始,几分之一秒后,它重新启动。所以我在每个文件的开头都会有半秒的卡顿,没有进一步前进,因为它总是回到开头。
媒体播放器及其循环音频的能力真的有问题吗?奇怪的口吃音池怎么样?
非常感谢您的帮助!
注意:Karthi_Heno 建议我这样做:
MediaPlayer mediaPlayer;
setVolumeControlStream(AudioManager.STREAM_MUSIC);
mediaPlayer = new MediaPlayer();
try {
AssetManager assetManager = getAssets();
AssetFileDescriptor descriptor = assetManager.openFd("music.ogg");
mediaPlayer.setDataSource(descriptor.getFileDescriptor(),
descriptor.getStartOffset(), descriptor.getLength());
mediaPlayer.prepare();
mediaPlayer.setLooping(true);
} catch (IOException e) {
textView.setText("Couldn't load music file, " + e.getMessage());
mediaPlayer = null;
}
但是,当我这样做时,getassets 给出 filenotfound,即使资产中有一个文件。对这个资产问题或我的音频循环问题有什么想法吗?
谢谢。是的,我是一个 Android 新手,好吧,甚至无法让声音循环。
Due to login confusion, i'm repeating this question. If any moderator sees this, i'd like to keep this one current, as I no longer can access my former login.
A bit of a problem has presented itself to me. I am trying to play a sound continously looping in my android app.
With MediaPlayer: MP3 plays alright, but there is a gap at the end which does not exist in the file. I read it had to do with the decoder, and that ogg should work. Tried using ogg, but still get the gap, which is definitely not on the file.
With SoundPool classes and ogg (using this fellow's interesting class: http://www.droidnova.com/creating-sound-effects-in-android-part-1,570.html),
the sound starts, and a fraction of a second later, it restarts. so I get a stutering half a second of the beginning of every file, without advancing further, because it is always going back to the beginning.
Is there something really wrong with media player and it's ability to loop audio? How about the freakishy stuttering soundpool?
Thank you very much for any assistance!
Note: Karthi_Heno suggested I do this:
MediaPlayer mediaPlayer;
setVolumeControlStream(AudioManager.STREAM_MUSIC);
mediaPlayer = new MediaPlayer();
try {
AssetManager assetManager = getAssets();
AssetFileDescriptor descriptor = assetManager.openFd("music.ogg");
mediaPlayer.setDataSource(descriptor.getFileDescriptor(),
descriptor.getStartOffset(), descriptor.getLength());
mediaPlayer.prepare();
mediaPlayer.setLooping(true);
} catch (IOException e) {
textView.setText("Couldn't load music file, " + e.getMessage());
mediaPlayer = null;
}
However, when i do this, getassets gives filenotfound, even though there IS a filein assets. any thoughts either on thisassets problem, or my audio loop question?
thanks. Yep, i'm an android newb alright, can't even get sound to loop alright.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论