简体   繁体   中英

Kivy & Buildozer: How to play audio while Android Application is loading?

Is there a way to play an audio while the Kivy application is loading while running on Android devices? That is play an audio while the presplash image , defined in the buildozer.spec file, is displayed on the screen.

There is no prebuilt way to do it. It would be possible to achieve by editing the Java code managing app loading, in the same place that the presplash image is set up.

As @inclement answered, this is by editing the Java code executed when the presplash image is displayed. The way to do that is simple.

  1. Open the Android project, created using Buildozer, in Android Studio.
  2. Add the code for playing audio either inside the onCreate() method of the PythonActivity, which is the main activity, or inside the showLoadingScreen() method used for displaying the presplash image while the app is loading.

Here is the modified onCreate() method for playing audio by passing its location in the device:

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.v(TAG, "My oncreate running");
    resourceManager = new ResourceManager(this);

    Log.v(TAG, "About to do super onCreate");
    super.onCreate(savedInstanceState);
    Log.v(TAG, "Did super onCreate");

    this.mActivity = this;
    Toast.makeText(this, "Working on the Kivy Project in Android Studio", Toast.LENGTH_LONG).show();
    this.showLoadingScreen();

    new UnpackFilesTask().execute(getAppRoot());
    MediaPlayer music = new MediaPlayer();
    try {
        music.setDataSource("/storage/emulated/0/music.mp3");
        music.prepare();
        music.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM