AdPlug song database
AdPlugDb is a song database for the AdPlug sound player library. Database control is managed through an application service, with interfaces provided for database control and various callbacks. A separate helper class is also provided, for managing service lifecycle and monitoring the connection state.
AdPlugDb is used in AndPlug music player application for Android devices.
- Android 4.0.3 (API Level: 15) or later (
ICE_CREAM_SANDWICH_MR1
) - Android Gradle Plugin 7.4.2) or later (
gradle:7.4.2
)
Setup steps:
- Check out a local copy of AdPlugDb repository
- Build library with Gradle, using Android Studio or directly from the command line
$ git clone https://github.com/omicronapps/AdPlugDb.git
AdPlugDb includes instrumented unit tests.
Located under adplugdb/src/androidTest
.
These tests are run on a hardware device or emulator, and verifies correct operation of the 'AdPlugDb' implementation as accessed through AdPlugDbService
. A set of songs need to be downloaded and installed in order to run the instrumented tests.
Setup steps:
cd AdPlugDB/adplugdb/src/androidTest/assets/
wget http://modland.com/pub/modules/Ad%20Lib/EdLib%20D00/MSK/en%20lille%20test.d00 en_lille_test_d00
wget http://modland.com/pub/modules/Ad%20Lib/EdLib%20D00/MSK/fresh.d00 fresh_d00
wget http://modland.com/pub/modules/Ad%20Lib/EdLib%20D00/JCH/gone.d00 gone_d00
wget http://modland.com/pub/modules/Ad%20Lib/EdLib%20D00/Drax/coop-Metal/super%20nova.d00 super_nova_d00
wget http://modland.com/pub/modules/Ad%20Lib/EdLib%20D00/JCH/the%20alibi.d00 the_alibi_d00
AdPlugDb is controlled through the following class and interfaces:
AdPlugDbController
- service management classIAdPlugDb
- database service interfaceIAdPlugDbCallback
- callback interface
Manages an instance of the AdPlugDbController
application service.
AdPlugDbController(IAdPlugDbCallback callback, Context context)
Constructor for the AdPlugDbController
class.
Arguments:
callback
- allows registering for callbacks through theIAdPlugDbCallback
interfacecontext
- required in order forAdPlugDbController
to manage the application service
void startDB()
Create and connect (bind) to AdPlugDbService
application service. While the service is running, AdPlugDbController
monitors its state, and provides callbacks to a registered listener through IAdPlugDbCallback
interface.
void stopDB()
Disconnect (unbind) from the application service.
IAdPlugDb getService()
Returns a reference to a AdPlugDbService
instance. Only valid between onServiceConnected()
and onServiceDisconnected()
callbacks of IAdPlugDbCallback
!
void getStatus()
Get current database status. Status returned through callback onStatus()
.
void index(String root)
Recursively index all songs and folders under provided path. Indexing completed when onStatus()
callback returns dbStatus.INITIALIZED
. Calls to list(String path)
are allowed while database is being initialized, but may result in list with some songs not yet indexed.
path
- path to root folder
void delete()
Delete database. Deletion completed when onStatus()
callback returns dbStatus.UNINITIALIZED
.
void list(String path, int sortby, int order, boolean quick, boolean hide, boolean random)
Get list of songs under provided path. Result returned through callback onList(List<AdPlugFile> songs)
.
path
- path to foldersortby
- sort criterionorder
- sort orderquick
- use existing databasehide
- hide unsupported filesrandom
- shuffle list
void playlist()
Get list of all playlists songs. Result returned through callback onPlaylist(List<AdPlugFile> playlists)
.
void add(String song, long length)
Add song to database.
song
- full path and name of songlength
- file length
void remove(String song)
Remove song from database.
song
- full path and name of song
void rename(String before, String after)
Rename song in database.
before
- current full path and name of songafter
- renamed full path and name of song
void getCount()
Get number of entries (songs and folders) in database. Count returned through callback onGetCount()
.
void search(String query);
Search in database. Result returned through callback onSearch(List<AdPlugFile> songs)
.
void onSongInfo(String song, String type, String title, String author, String desc, long length, long songlength, int subsongs, boolean valid, boolean playlist)
Reverse callback from application to provide information on song, when so requested through requestInfo()
.
Callback interface from AdPlugDb
database instance.
void onServiceConnected()
Application service connected. AdPlugDbController.getService()
may be used to retrieve a reference to a AdPlugDbService
instance following this callback.
void onServiceDisconnected()
Application service disconnected. Any reference to the AdPlugDbService
instance is now invalid.
void onStatusChanged(dbStatus status)
Notification callback of new AdPlugDb
state.
state
- current state
void requestInfo(String name, long length)
Request from AdPlugDb
instance for AdPlug song information.
name
- full path and name of songlength
- file length
void onList(List<AdPlugFile> songs)
Callback from AdPlugDb
with list of songs, following request through list()
.
songs
- list of songs in requested folder
void onPlaylist(List<AdPlugFile> playlists)
Callback from AdPlugDb
with list of playlists, following request through playlist()
.
playlists
- list of all playlists
void onStatus(dbStatus status)
Callback from AdPlugDb
with database status, following request through getStatus()
.
status
- current database status
void onGetCount(long count)
Callback from AdPlugDb
with number of entries, following request through getCount()
.
count
- number of entries (songs and folders) in database
void onSearch(List<AdPlugFile> songs)
Callback from AdPlugDb
with list of songs, following request through search()
.
songs
- list of songs
Implement IAdPlugDbCallback
callback interface:
import com.omicronapplications.adplugdb.IAdPlugDbCallback;
import com.omicronapplications.adplugdb.IAdPlugDb;
class AdPlugDbCallback implements IAdPlugDbCallback {
@Override
public void onServiceConnected() {
AdPlugDbController controller;
// Bound to AdPlugDbService, retrieve IAdPlugDb instance
IAdPlugDb service = controller.getService();
}
@Override
public void onServiceDisconnected() {
// Unbound from AdPlugDbService, IAdPlugDb instance unusable
}
@Override
public void onStatusChanged(dbStatus status) {
}
@Override
public void requestInfo(String name, long length) {
}
@Override
public void onList(List<AdPlugFile> songs) {
}
@Override
public void onStatus(dbStatus status) {
}
@Override
public void onGetCount(long count) {
}
@Override
public onSearch(List<AdPlugFile> songs) {
}
}
Create an AdPlugDbController
instance to bind to AdPlugDbService
:
import com.omicronapplications.adplugdb.AdPlugDbController;
IAdPlugDbCallback callback = new AdPlugDbCallback();
AdPlugDbController controller = new AdPlugDbController(callback, getApplicationContext());
controller.startDB();
Retrieve IAdPlugDb
object on IAdPlugDbCallback.onServiceConnected()
callback, and index songs in folder:
import com.omicronapplications.adplugdb.IAdPlugDb;
AdPlugDbController controller;
IAdPlugDb service = controller.getService();
service.index(dir.getAbsolutePath());
Request list of songs in folder:
service.list(dir.getAbsolutePath());
Destroy AdPlugDbController
instance to unbind from AdPlugDbService
:
controller.destroy();
Copyright (C) 2020-2024 Fredrik Claesson
- 1.0.0 Initial release
- 1.1.0 Support for quick listings and for hiding invalid files from list
- 1.2.0 Extended sort options
- 1.3.0 Added support for retrieving playlists and random shuffle
- 1.4.0 Add search and rename functions, bug fixes, change to Apache License Version 2.0
- 1.5.0 Include playlists when hiding invalid files
AdPlugDb is licensed under Apache License Version 2.0.