[英]android - MediaPlayer stops working at some point
I have been working on an app, and it involves sound. 我一直在开发一个应用程序,它涉及声音。 Now, I use this to start it: 现在,我用它来启动它:
final MediaPlayer tick = MediaPlayer.create(getApplicationContext(), R.raw.tick_16);
tick.start();
But for some reason, after some time (depends on the device, on HTC One it is a few seconds and in others a few minuets) all sound stopps. 但是由于某种原因,一段时间后(取决于设备,在HTC One上是几秒钟,在其他情况下是几分钟),所有声音都停止了。
What is the cause of it and how can I solve it? 原因是什么?如何解决?
Use this tutorial to play audio : http://www.tutorialspoint.com/android/android_mediaplayer.htm 使用本教程播放音频: http : //www.tutorialspoint.com/android/android_mediaplayer.htm
you may be use tick.start(); 您可能会使用tick.start(); in onResume() method of your activity class 在活动类的onResume()方法中
尝试在Service
启动MediaPlayer
并在startForeground()
内startForeground()
Notification
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.