Permalink
Browse files

handling start time on play, fix for issue where player reset while p…

…reparing
  • Loading branch information...
1 parent 99fa6a7 commit 2807dd2121b9d70e59ce21016f9681803709feaf @rebeccanesson rebeccanesson committed May 28, 2013
@@ -18,5 +18,3 @@
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
-
--keep public class * implements org.prx.android.playerhater.plugins.PlayerHaterPlugin { *; }
View
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<lint>
+</lint>
View
@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
@@ -151,8 +151,9 @@ public static String getStateName(int state) {
case PREPARED:
return "prepared";
case PREPARING:
+ return "preparing";
case PREPARING_CONTENT:
- return "preparing";
+ return "preparing content";
case STARTED:
return "started";
case STOPPED:
@@ -16,6 +16,8 @@
package org.prx.android.playerhater.player;
+import java.io.IOException;
+
import org.prx.android.playerhater.util.Log;
import android.content.Context;
@@ -33,8 +35,11 @@ public static final Synchronous synchronous(MediaPlayerWithState mediaPlayer) {
private boolean mShouldPlayWhenPrepared;
private int mShouldSkipWhenPrepared;
+ private boolean mShouldPrepareWhenPrepared;
private OnPreparedListener mOnPreparedListener;
private OnSeekCompleteListener mOnSeekCompleteListener;
+ private Uri mDataSourceUri;
+ private Context mPrepareContext;
public Synchronous(MediaPlayerWithState player) {
super(player);
@@ -73,6 +78,9 @@ public void onSeekComplete(MediaPlayer mp) {
public boolean prepare(Context context, Uri uri) {
mShouldPlayWhenPrepared = false;
mShouldSkipWhenPrepared = 0;
+ mShouldPrepareWhenPrepared = false;
+ mDataSourceUri = uri;
+ mPrepareContext = context;
switch (getState()) {
case IDLE:
try {
@@ -89,6 +97,11 @@ public boolean prepare(Context context, Uri uri) {
e1.printStackTrace();
}
break;
+ case PREPARING:
+ if (!uri.equals(mDataSourceUri)) {
+ mShouldPrepareWhenPrepared = true;
+ }
+ break;
default:
Log.d("About to reset with state " + getStateName());
reset();
@@ -124,7 +137,7 @@ public boolean prepareAndPlay(Context context, Uri uri, int position) {
@Override
public void start() {
- if (getState() == PREPARING || getState() == PREPARING_CONTENT) {
+ if (getState() == PREPARING || getState() == PREPARING_CONTENT || getState() == LOADING_CONTENT) {
mShouldPlayWhenPrepared = true;
} else if (getState() == INITIALIZED) {
mShouldPlayWhenPrepared = true;
@@ -203,6 +216,9 @@ private void startIfNecessary() {
} else if (mShouldPlayWhenPrepared) {
start();
mShouldPlayWhenPrepared = false;
+ } else if (mShouldPrepareWhenPrepared) {
+ prepare(mPrepareContext, mDataSourceUri);
+ mPrepareContext = null;
}
}
@@ -27,6 +27,7 @@
import android.app.Activity;
import android.content.Context;
import android.net.Uri;
+import android.util.Log;
public class BoundPlayerHater extends PlayerHater {
@@ -325,6 +326,7 @@ public Song nowPlaying() {
if (sPlayQueue.getNowPlaying() != null) {
return sPlayQueue.getNowPlaying();
} else if (mPlayerHater == null) {
+ Log.d(TAG, "can't get now playing because player hater is null");
return null;
}
return mPlayerHater.nowPlaying();
@@ -63,7 +63,7 @@ public boolean stop() throws RemoteException {
@Override
public boolean play(final int startTime) throws RemoteException {
- return mPlayerHater.play();
+ return mPlayerHater.play(startTime);
}
@Override
@@ -163,6 +163,11 @@ public void onSongChanged(Song song) {
@Override
public void onChangesComplete() {
+ if (getPlayerHater().getState() != -1) {
+ Log.d(MediaPlayerWrapper.getStateName(getPlayerHater().getState()));
+ } else {
+ Log.d("impossible state");
+ }
switch (getPlayerHater().getState()) {
case Player.STARTED:
mListener.onPlaying(mSong, getPlayerHater().getCurrentPosition());
@@ -35,6 +35,7 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
+import android.util.Log;
import android.view.KeyEvent;
@SuppressWarnings("unused")
@@ -97,6 +98,7 @@ public boolean play(Song song, int position) {
mSongQueue.skipToEnd();
}
+ Log.d(TAG, "" + getNowPlaying().getTitle());
if (getMediaPlayer().prepareAndPlay(getApplicationContext(),
getNowPlaying().getUri(), position)) {
startClockThread();

0 comments on commit 2807dd2

Please sign in to comment.