diff --git a/core/src/main/java/com/aocate/media/MediaPlayer.java b/core/src/main/java/com/aocate/media/MediaPlayer.java index c73c5219e..79e63d03d 100644 --- a/core/src/main/java/com/aocate/media/MediaPlayer.java +++ b/core/src/main/java/com/aocate/media/MediaPlayer.java @@ -35,6 +35,8 @@ import java.util.concurrent.locks.ReentrantLock; import de.danoeh.antennapod.core.BuildConfig; public class MediaPlayer { + public static final String TAG = "com.aocate.media.MediaPlayer"; + public interface OnBufferingUpdateListener { public abstract void onBufferingUpdate(MediaPlayer arg0, int percent); } @@ -109,6 +111,36 @@ public class MediaPlayer { return list.size() > 0; } + /** + * Returns an explicit Intent for a service that accepts the given Intent + * or null if no such service was found. + * + * @param context The application's environment. + * @param action The Intent action to check for availability. + * @return The explicit service Intent or null if no service was found. + */ + public static Intent getPrestoServiceIntent(Context context, String action) { + final PackageManager packageManager = context.getPackageManager(); + final Intent actionIntent = new Intent(action); + List list = packageManager.queryIntentServices(actionIntent, + PackageManager.MATCH_DEFAULT_ONLY); + if (list.size() > 0) { + ResolveInfo first = list.get(0); + if (first.serviceInfo != null) { + Intent intent = new Intent(); + intent.setComponent(new ComponentName(first.serviceInfo.packageName, + first.serviceInfo.name)); + Log.i(TAG, "Returning intent:" + intent.toString()); + return intent; + } else { + Log.e(TAG, "Found service that accepts " + action + ", but serviceInfo was null"); + return null; + } + } else { + return null; + } + } + /** * Indicates whether the Presto library is installed * diff --git a/core/src/main/java/com/aocate/media/ServiceBackedMediaPlayer.java b/core/src/main/java/com/aocate/media/ServiceBackedMediaPlayer.java index 702a23b0f..0e27a8014 100644 --- a/core/src/main/java/com/aocate/media/ServiceBackedMediaPlayer.java +++ b/core/src/main/java/com/aocate/media/ServiceBackedMediaPlayer.java @@ -83,7 +83,7 @@ public class ServiceBackedMediaPlayer extends MediaPlayerImpl { super(owningMediaPlayer, context); Log.d(SBMP_TAG, "Instantiating ServiceBackedMediaPlayer 87"); this.playMediaServiceIntent = - new Intent(INTENT_NAME); + MediaPlayer.getPrestoServiceIntent(context, INTENT_NAME); this.mPlayMediaServiceConnection = new ServiceConnection() { public void onServiceConnected(ComponentName name, IBinder service) { IPlayMedia_0_8 tmpPlayMediaInterface = IPlayMedia_0_8.Stub.asInterface((IBinder) service); @@ -135,6 +135,7 @@ public class ServiceBackedMediaPlayer extends MediaPlayerImpl { Log.d(SBMP_TAG, "Connecting PlayMediaService 124"); if (!ConnectPlayMediaService()) { + Log.e(SBMP_TAG, "bindService failed"); ServiceBackedMediaPlayer.this.error(MediaPlayer.MEDIA_ERROR_UNKNOWN, 0); } } @@ -149,6 +150,7 @@ public class ServiceBackedMediaPlayer extends MediaPlayerImpl { Log.d(SBMP_TAG, "Binding service"); return mContext.bindService(playMediaServiceIntent, mPlayMediaServiceConnection, Context.BIND_AUTO_CREATE); } catch (Exception e) { + Log.e(SBMP_TAG, "Could not bind with service", e); return false; } } else {