Giter Site home page Giter Site logo

Comments (2)

rivercat68 avatar rivercat68 commented on June 30, 2024

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()");
}

}
`

from android-audio-visualizer.

GautamChibde avatar GautamChibde commented on June 30, 2024

@mohamadkhalaf @rivercat68 check this example activity and service provided here.

You will also need to update to library version to 2.0.1

from android-audio-visualizer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.