开发者

Display an image in default media player of Android

开发者 https://www.devze.com 2023-03-01 13:39 出处:网络
Here is my code. First I recorded an audio file and started playing it. For playing the audio file /**

Here is my code. First I recorded an audio file and started playing it. For playing the audio file

/**
 * 
 * play the recorded audio
 *
 */
    public void playAudio() {
    try {

        Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
        Uri data = Uri.parse(path);
        intent.setDataAndType(data, "audio/mp3");
        startActivity(intent);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
    } catch (Exception e) {
        // TODO: handle exception
    }
    }

and the outp开发者_开发知识库ut is calling the default media player of device. Here I need to show an image in that media player in the place of album image.

Here is an image of what I need:

Display an image in default media player of Android


The default media player is using the following code to retrieve the album art of a song.

Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
Uri uri = ContentUris.withAppendedId(sArtworkUri, album_id);
ContentResolver res = context.getContentResolver();
InputStream in = res.openInputStream(uri);
Bitmap artwork = BitmapFactory.decodeStream(in);

where album_id is the albumd id of the song. So in order to show an album art the default player should know the album id and check if there is album art associated with this id. So if you want to show artwork you have to insert your file in android's database and then play it from there.

0

精彩评论

暂无评论...
验证码 换一张
取 消