Audio visualizer and services
mohamadkhalaf opened this issue · 2 comments
hello, how I can create visualizer for a media player running in service,
I went to add visualizer to my main activity and get media player from service to run the visualizer
thanks
Hi I am wondering how to get this working with a service as well. It works really when running the MediapPayer in the same activity. Below is the code for my service. Thanks for any help you can give.
`import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.IBinder;
import android.util.Log;
@SuppressWarnings({"WeakerAccess", "CanBeFinal", "SameReturnValue", "unused"})
public class BackgroundSoundService extends Service {
private static final String TAG = "BackgroundSoundService";
public MediaPlayer player;
public IBinder onBind(Intent arg0) {
Log.i(TAG, "onBind()" );
return null;
}
@Override
public void onCreate() {
super.onCreate();
Log.i(TAG, "onCreate() , service started...");
}
public int onStartCommand(Intent intent, int flags, int startId) {
String stUrl = intent.getStringExtra("URL");
Uri uri = Uri.parse( stUrl );
player = MediaPlayer.create(this, uri);
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() {
player.pause();
player.stop();
player.release();
Log.i(TAG, "onPause()");
}
@Override
public void onDestroy() {
player.stop();
player.release();
Log.i(TAG, "onCreate() , service stopped...");
}
@Override
public void onLowMemory() {
Log.i(TAG, "onLowMemory()");
}
}
`
@mohamadkhalaf @rivercat68 check this example activity and service provided here.
You will also need to update to library version to 2.0.1