Android media player stop playing while in background

后端 未结 1 554
太阳男子
太阳男子 2021-01-21 02:35

I\'m making music player app with simple functionality. But when I listen music on my phone with Android 6, sometimes music stops playing until I turn on display again with powe

1条回答
  •  有刺的猬
    2021-01-21 03:38

    Unless you use foreground service, the system will kill your process and mediaplayer will stop. below is a part from from a foreground service ( notification example).

    builder.setContentTitle(aMessage)                           // required
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentText(this.getString(R.string.app_name))  // required
            .setAutoCancel(false)
            .setContentIntent(pendingIntent)
            .setVibrate(new long[]{0L})
            .setPriority(Notification.PRIORITY_HIGH);
    int mId = 1489;
    startForeground(mId, builder.build());
    

    The above code is tested and working fine.

    0 讨论(0)
提交回复
热议问题