将 MediaPlayer 与计时器一起使用
我目前有一个计时器,我想在计时器结束时播放声音文件。但是它只播放我存储的音频文件的一小部分。我的代码中没有任何内容告诉文件停止播放,所以我不知道为什么会发生这种情况。
我从这个开始:
public class DrinkinzActivity extends Activity {
/** Called when the activity is first created. */
Timer myTimer;
public MediaPlayer mMediaPlayer;
然后在 onCreate 方法中我有这个:
mMediaPlayer = new MediaPlayer();
mMediaPlayer = MediaPlayer.create(getBaseContext(), R.raw.soundfile);
然后当计时器用完时,我有这个:
mMediaPlayer.start();
我什至还没有到达用户可以选择要播放哪个声音文件或使用铃声的部分反而。我有什么遗漏的吗?
I currently have a timer that I want to play a sound file when the timer ends. However it's only playing a fraction of audio file I have stored. I have nothing in the code that tells the file to stop playing, so I don't know why this is happening.
I start out with this:
public class DrinkinzActivity extends Activity {
/** Called when the activity is first created. */
Timer myTimer;
public MediaPlayer mMediaPlayer;
Then in the onCreate method I have this:
mMediaPlayer = new MediaPlayer();
mMediaPlayer = MediaPlayer.create(getBaseContext(), R.raw.soundfile);
Then when the timer runs out, I have this:
mMediaPlayer.start();
I haven't even gotten to the part where the user can pick which sound file to play, or use a ringtone instead. Is there something I'm missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显然我回答了我自己的问题。我使用的音频文件是 wma 格式,而 android(Linux)并不喜欢这种格式。我将其重新格式化为 mp3,现在工作正常。它与计时器无关。
Apparently I answered my own question. The audio file I was using was in wma format, and android (being Linux) didn't really like that. I reformatted it to mp3 and it works fine as of right now. It had nothing to do with the timer.