将 MediaPlayer 与计时器一起使用

发布于 2024-11-30 17:52:59 字数 571 浏览 4 评论 0原文

我目前有一个计时器,我想在计时器结束时播放声音文件。但是它只播放我存储的音频文件的一小部分。我的代码中没有任何内容告诉文件停止播放,所以我不知道为什么会发生这种情况。

我从这个开始:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笔落惊风雨 2024-12-07 17:52:59

显然我回答了我自己的问题。我使用的音频文件是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文