Ive implemented a mediaplayer and mediacontroller that streams a mp3 url. However my device on the TMobile network doesnt get a great 3G signal so it operates on EDGE. Im assuming that the mediaplayer is crashing because the stream is too slow or incomplete, is there a timeout I can set?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
There is no timeout method in MediaPlayer, but you can implement it yourself - there are variety of ways you can do that. I suggest one of them, that I used myself and it worked for me - BroadcastReceiver Code would look like that:
In your activity/service/fragment you add this line:
You will need to implement hour/min/second checking logic yourself, but it's easily done with libraries like Joda Time. And don't forget to add to your manifest:
Ps, my solution is not perfect, but I have not seen any good answers for this question, so if find one, please share it.
Indeed Mediaplayer takes some time to buffer and on slow networks that can lead to problems.
You cannot control this process, there is no user set timeout, but you can make sure it doesn't crash your app by catching all exception that methods such as setDataSource(), prepare(), prepareAsync(), and start() can throw.
You can also use prepare() instead of prepareAsync() on MediaPlayer and put it inside asyncTask or worker thread; then you can inmplement timeout functionality by yourself. I will add a code sample later, but the idea is clear I think.