在android studio中播放媒体播放器

时间:2019-12-03 03:01:30

标签: android audio service

这是我的代码,用于在后台使用原始音频在后台播放媒体音频播放器,但我想对其进行更改,因此要使应用程序无法访问手机的外部存储,如何将代码更改为此

公共类BackgroundSoundService扩展了服务{

private static final String TAG = "forSoundService";
MediaPlayer player;

public IBinder onBind(Intent arg0) {
    Log.i(TAG, "onBind()" );
    return null;
}

@Override
public void onCreate() {
    super.onCreate();
   player = MediaPlayer.create(this, R.raw.jorgesys_song);
    player.setLooping(true); // Set looping
    player.setVolume(100,100);
    Log.i(TAG, "onCreate() , service started...");

}
public int onStartCommand(Intent intent, int flags, int startId) {
    player.start();
    return Service.START_STICKY;
}

public IBinder onUnBind(Intent arg0) {
    Log.i(TAG, "onUnBind()");
    return null;
}

public void onStop() {
    Log.i(TAG, "onStop()");
}
public void onPause() {
    Log.i(TAG, "onPause()");
}
@Override
public void onDestroy() {
    player.stop();
    player.release();
    Toast.makeText(this, "Service stopped...", Toast.LENGTH_SHORT).show();
    Log.i(TAG, "onCreate() , service stopped...");
}

@Override
public void onLowMemory() {
    Log.i(TAG, "onLowMemory()");
}

}

0 个答案:

没有答案