Commit b1bec758 authored by John Mooring's avatar John Mooring Committed by Sébastien Toque

Implemented album artwork acquisition.

Signed-off-by: Sébastien Toque's avatarSébastien Toque <xilasz@gmail.com>
parent ae0047a9
......@@ -24,7 +24,7 @@
android:layout_height="match_parent"
android:layout_width="0dip"
android:layout_weight="1"
android:background="#ffffff"
android:background="#00ffffff"
android:layout_marginLeft="15dip"
android:layout_marginTop="15dip"
android:id="@+id/cover" />
......
package org.videolan.vlc.android;
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
......@@ -27,6 +28,7 @@ public class AudioPlayerActivity extends Activity implements AudioPlayer {
private AudioServiceController mAudioController;
private boolean mIsTracking = false;
private String lastTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -47,7 +49,7 @@ public class AudioPlayerActivity extends Activity implements AudioPlayer {
mTimeline = (SeekBar) findViewById(R.id.timeline);
mAudioController = AudioServiceController.getInstance();
lastTitle = "";
}
@Override
......@@ -69,8 +71,15 @@ public class AudioPlayerActivity extends Activity implements AudioPlayer {
if (!mAudioController.hasMedia())
finish();
// mCover....
mTitle.setText(mAudioController.getTitle());
if (!mAudioController.getTitle().equals(lastTitle)) {
Bitmap cover = mAudioController.getCover();
if (cover != null)
mCover.setImageBitmap(cover);
else
mCover.setImageResource(R.drawable.cone);
}
lastTitle = mAudioController.getTitle();
mTitle.setText(lastTitle);
mArtist.setText(mAudioController.getArtist());
mAlbum.setText(mAudioController.getAlbum());
int time = (int) mAudioController.getTime();
......
package org.videolan.vlc.android;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
......@@ -7,11 +8,17 @@ import java.util.Stack;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.RemoteException;
import android.provider.MediaStore;
import android.util.Log;
public class AudioService extends Service {
......@@ -54,7 +61,7 @@ public class AudioService extends Service {
}
/**
* Handle libvlc asynchronous events
* Handle libvlc asynchronous events
*/
private Handler mEventHandler = new Handler() {
......@@ -265,6 +272,39 @@ public class AudioService extends Service {
return null;
}
public Bitmap getCover() {
if (mCurrentMedia != null) {
try {
ContentResolver contentResolver = getContentResolver();
Uri uri = android.provider.MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI;
Cursor cursor = contentResolver.query(uri, new String[] {
MediaStore.Audio.Albums.ALBUM,
MediaStore.Audio.Albums.ALBUM_ART },
MediaStore.Audio.Albums.ALBUM + " LIKE ?",
new String[] { mCurrentMedia.getAlbum() }, null);
if (cursor == null) {
// do nothing
} else if (!cursor.moveToFirst()) {
// do nothing
} else {
int titleColumn = cursor.getColumnIndex(android.provider.MediaStore.Audio.Albums.ALBUM_ART);
String albumArt = cursor.getString(titleColumn);
Bitmap b = BitmapFactory.decodeFile(albumArt);
if (b != null)
return b;
}
File f = new File(mCurrentMedia.getPath());
for (File s : f.getParentFile().listFiles()) {
if (s.getAbsolutePath().endsWith("png") ||
s.getAbsolutePath().endsWith("jpg"))
return BitmapFactory.decodeFile(s.getAbsolutePath());
}
} catch (Exception e) {
}
}
return null;
}
@Override
public void addAudioCallback(IAudioServiceCallback cb)
throws RemoteException {
......@@ -287,7 +327,6 @@ public class AudioService extends Service {
@Override
public int getLength() throws RemoteException {
// TODO Auto-generated method stub
return (int) mLibVLC.getLength();
}
......
......@@ -82,7 +82,6 @@ public class AudioServiceController implements AudioPlayerControl {
/**
* Bind to audio service if it is running
* @return true if the binding was successful.
*/
public void bindAudioService() {
if (mAudioServiceBinder == null) {
......@@ -252,7 +251,12 @@ public class AudioServiceController implements AudioPlayerControl {
@Override
public Bitmap getCover() {
return null;
try {
return mAudioServiceBinder.getCover();
} catch (RemoteException e) {
Log.e(TAG, "remote procedure call failed: getCover()");
return null;
}
}
@Override
......
......@@ -23,6 +23,7 @@ interface IAudioService {
String getAlbum();
int getTime();
int getLength();
Bitmap getCover();
void addAudioCallback(IAudioServiceCallback cb);
void removeAudioCallback(IAudioServiceCallback cb);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment