Back

CreateMediaStore

Hello World
Content:
- Methods

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();
}
Copy All       Run      

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();
}
Copy All       Run      

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();
}
Copy All       Run      

Methods

The following methods are available on the MediaStore object:

GetAlbumArt( image, id, options ) → Boolean
GetSongArt( image, id, options ) → Boolean
GetType() → String: “MediaStore”
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”
Object: { COMMAND }
app object: Image
List: [{ album, id, albumArt, artist, numSongs, firstYear, lastYear }]
List: [{ id, artist, numAlbums, numTracks }]
List: [{ title, id, duration, size, uri, album, albumID, artist, artistId }]
function( result )
function( result )
function( result )
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.GetAlbumArt
Loads the album image to an existing image.
med.GetSongArt
Loads 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.