Background music Android

后端 未结 9 1568
夕颜
夕颜 2020-12-03 01:57

Okey, this is my problem. I have one service class where Ive managed to create media player to play music in background all time. Here is code:

package com.t         


        
9条回答
  •  长情又很酷
    2020-12-03 02:41

    AsyncTasks are good just for very short clips, but if it is a music file you will face problems like:

    • You will not be able to stop/pause the music in middle. For me that is a real problem.

    Here is few line from Android developers page about AsyncTasks

    AsyncTasks should ideally be used for short operations (a few seconds at the most.) If you need to keep threads running for long periods of time, it is highly recommended you use the various APIs provided by the java.util.concurrent package such as Executor, ThreadPoolExecutor and FutureTask.

    So currently I am looking in to other options and update the answer once I find the solution.

提交回复
热议问题