Skip to main content

🎬 Background Playback with VdoCipher SDK 🎶

Background playback allows media to continue playing seamlessly while multitasking or switching apps. This feature ensures that music, podcasts, or videos remain uninterrupted, even when the screen is locked or the app is exited. Starting with SDK version 1.27.0, the VdoCipher Android SDK offers smooth support for background playback, enabling uninterrupted media enjoyment across various device activities. 🌟

⚙️ Configuring Background Playback

🎵 Playback Modes

The VdoCipher SDK offers three playback modes, each providing a different level of persistence:

The media will immediately pause when the user closes or navigates away from the player screen.

Ideal for applications like e-learning platforms, where it's important for users to stay focused on the content without switching between apps.📚

🛠️ How to Implement?

1. Add Permission for Media Playback Service

To enable background playback in your app, you need to declare the android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK permission in your AndroidManifest.xml file when target SDK version is set as 34 and higher.

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />

<application
..>
..
</application>
</manifest>

2. Configure Background Playback

To configure background playback, use the following code in your application class:

public class MyApplication extends Application {
@Override public void onCreate() {
super.onCreate();
new VdoPlayerSetting.Builder()
// Choose the mode that fits your app
.setPlaybackBehavior(VdoPlaybackMode.CONTINUE_PLAYBACK_ON_BACK_PRESS)
.build()
.applySettings(getApplicationContext());
}
}
Choose the mode that fits your app

Replace CONTINUE_PLAYBACK_ON_BACK_PRESS in the snippet with the mode that best suits your app's needs:

  • DEFAULT: Stops playback when the player screen is closed.
  • CONTINUE_PLAYBACK_ON_BACK_PRESS: Continues playback when the app is minimized but stops when fully closed.
  • CONTINUE_PLAYBACK_ON_APP_EXIT: Keeps playback running even after the app is closed.

If playback behavior is not set, the player will default to DEFAULT behavior.