Android how to keep my music playing even when the phone is lock and sleep

吃可爱长大的小学妹 提交于 2019-12-13 02:45:32

问题


am new in mobile app development, but have try do develop online radio app using Android Studio, but when the app is playing the sound from Icecast it use to stop when the phone is lock and sleep.

Also i find it difficult to set the accurate width that can march any app, the one that i set only work for Small Android Screen. The code full the width of small android phone with android 4.0 but on large screen android phone i can see some space beside and at the bottom of the screen.

Main XML Code


回答1:


You should use MediaSession since its designed to help you control Media playing and controlling media playback. Check the reference and follow steps for using MediaSession.




回答2:


Universal Android Music Player

This sample shows how to implement an audio media app that works across multiple form factors and provide a consistent user experience on Android phones, tablets, Android Auto, Android Wear, Android TV and Google Cast devices.

It also work on lock screen.

link to sample app and source code

hope this will help you.



来源:https://stackoverflow.com/questions/46427463/android-how-to-keep-my-music-playing-even-when-the-phone-is-lock-and-sleep

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!