The MediaStore is used to query audio information from the android provider or from the device in the “/sdcard/Music” folder.
med = app.CreateMediaStore( ) → app object: MediaStore
Example - Query Artists
function OnStart()
{
lay = app.CreateLayout( "linear", "VCenter,FillXY" );
lst = app.CreateList( "", 1, .9 );
lay.AddChild( lst );
app.AddLayout( lay );
app.ShowProgress( "Query Artists" );
media = app.CreateMediaStore();
media.SetOnArtistsResult( media_OnArtistsResult );
media.QueryArtists( "", "artist", "external" );
}
function media_OnArtistsResult( result )
{
result.forEach( function( m )
{
var s = "";
for( var k in m ) s += k + ": " + m[k] + "\n";
lst.AddItem( m.artist, s.slice( 0, -4 ), "" );
} );
app.HideProgress();
}
Example - Query Albums
function OnStart()
{
lay = app.CreateLayout( "linear", "VCenter,FillXY" );
lst = app.CreateList( "", 1, .9 );
lst.SetColumnWidths( 0.3 );
lst.SetIconSize( 0.2 );
lay.AddChild( lst );
app.AddLayout( lay );
app.ShowProgress( "Query Albums" );
media = app.CreateMediaStore();
media.SetOnAlbumsResult( media_OnAlbumsResult );
media.QueryAlbums( "", "album", "external" );
}
function media_OnAlbumsResult( result )
{
result.forEach( function( m )
{
var s = "";
for( var k in m ) s += k + ": " + m[k] + "\n";
lst.AddItem( m.album, s.slice( 0, -4 ), m.albumArt == "null" ? "audio" : m.albumArt );
} );
app.HideProgress();
}
Example - Query Media
function OnStart()
{
lay = app.CreateLayout( "linear", "VCenter,FillXY" );
lst = app.CreateList( "", 1, .9 );
lay.AddChild( lst );
app.AddLayout( lay );
app.ShowProgress( "Query Media" );
media = app.CreateMediaStore();
media.SetOnMediaResult( media_OnMediaResult );
media.QueryMedia( "", "title", "external" );
}
function media_OnMediaResult( result )
{
result.forEach( function( m )
{
var s = "";
for( var k in m ) s += k + ": " + m[k] + "\n";
lst.AddItem( m.title, s.slice( 0, -4 ), "" );
} );
app.HideProgress();
}
Methods
The following methods are available on the MediaStore object:
Number: integer
String: sql code
String: “internal” or “external”
String: coloumns: “album”, “_id”, “albumArt”, “artist”, “numSongs”, “firstYear”, “lastYear”
String: coloumns: “_id”, “artist”, “numAlbums”, “numTracks”
String: coloumns: “title”, “_id”, “duration”, “size”, “uri”, “album”, “albumID”, “artist”, “artistId”
med.Batch
Batch method calls to be able to set all object's properties at once.
Note that you need to specify each parameter (use “” or null to leave some out)
Inherited methods can be called by appending an underscore to the function name (ie. txt.Batch({ SetBackColor_: [“red”] })
med.GetAlbumArtLoads the album image to an existing
image.
med.GetSongArtLoads the song image to an existing
image.
med.GetType
Returns the control class name.
med.QueryAlbums
Search for media albums.
med.QueryArtists
Search for media artists.
med.QueryMedia
Search for media.
med.SetOnAlbumsResult
Define a callback function which is called when an album query has finished.
med.SetOnArtistsResult
Define a callback function which is called when a artist query has finished.
med.SetOnMediaResult
Define a callback function which is called when a media query has finished.