Skip to content Skip to sidebar Skip to footer

Android Media Player Stop Playing While In Background

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 power bu

Solution 1:

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(newlong[]{0L})
        .setPriority(Notification.PRIORITY_HIGH);
int mId = 1489;
startForeground(mId, builder.build());

The above code is tested and working fine.

Post a Comment for "Android Media Player Stop Playing While In Background"