Skip to content

Commit

Permalink
modifications to fail without crashing
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccanesson committed Aug 22, 2013
1 parent 16ff43b commit 44198cf
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 25 deletions.
13 changes: 7 additions & 6 deletions src/main/java/org/prx/playerhater/PlaybackService.java
Expand Up @@ -211,10 +211,11 @@ protected synchronized void setMediaPlayer(
}

@Override
synchronized protected PlaylistSupportingPlayer getMediaPlayer() {
if (peekMediaPlayer() == null) {
return null;
}
return peekMediaPlayer();
}
synchronized protected PlaylistSupportingPlayer getMediaPlayer() {
if (peekMediaPlayer() == null) {
PlaylistSupportingPlayer player = mMediaPlayerPool.getPlayer(getApplicationContext(), nowPlaying().getUri());
setMediaPlayer(player);
}
return peekMediaPlayer();
}
}
20 changes: 13 additions & 7 deletions src/main/java/org/prx/playerhater/mediaplayer/StatelyPlayer.java
Expand Up @@ -19,6 +19,7 @@

import org.prx.playerhater.util.Log;

import android.content.ContentProviderClient;
import android.content.Context;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnBufferingUpdateListener;
Expand Down Expand Up @@ -380,15 +381,16 @@ public synchronized void setDataSource(final Context context, final Uri uri)
IllegalArgumentException, SecurityException {
if (uri.getScheme().equals("content")) {
setState(LOADING_CONTENT);
final ContentProviderClient contentProviderClient = context.getContentResolver().acquireContentProviderClient(uri);
(new Thread() {
@Override
public void run() {
synchronized (StatelyPlayer.this) {
try {
ParcelFileDescriptor fd = context
.getContentResolver().openFileDescriptor(
ParcelFileDescriptor fd = contentProviderClient.openFile(
uri, "r");
mMediaPlayer.setDataSource(fd.getFileDescriptor());
// ParcelFileDescriptor fd = context.getContentResolver().openFileDescriptor(uri, "r");
// mMediaPlayer.setDataSource(fd.getFileDescriptor());
int state = getInternalState();
setState(INITIALIZED);
if ((state & PREPARING_CONTENT) != 0) {
Expand All @@ -410,10 +412,14 @@ public void run() {
}
}
}).start();
} else {
mMediaPlayer.setDataSource(uri.toString());
setState(INITIALIZED);
}
contentProviderClient.release();
} else if (uri.getScheme().equals("http") || uri.getScheme().equals("https")) {
mMediaPlayer.setDataSource(uri.toString());
setState(INITIALIZED);
} else {
mMediaPlayer.setDataSource(context, uri);
setState(INITIALIZED);
}
}

@Override
Expand Down
Expand Up @@ -162,11 +162,15 @@ public void onChangesComplete() {
}

private void onTick() {
if (getPlayerHater().getState() == PlayerHater.STATE_PLAYING) {
mListener.onPlaying(getPlayerHater().nowPlaying(), getPlayerHater()
.getCurrentPosition());
} else if (getPlayerHater().getState() == PlayerHater.STATE_STREAMING) {
mListener.onStreaming(getPlayerHater().nowPlaying());
try {
if (getPlayerHater().getState() == PlayerHater.STATE_PLAYING) {
mListener.onPlaying(getPlayerHater().nowPlaying(), getPlayerHater()
.getCurrentPosition());
} else if (getPlayerHater().getState() == PlayerHater.STATE_STREAMING) {
mListener.onStreaming(getPlayerHater().nowPlaying());
}
} catch (java.lang.IllegalStateException e) {
// do nothing
}
}
}
Expand Up @@ -68,6 +68,14 @@ public void setClient(IPlayerHaterClient client) {
}
if (client != null) {
mClient = new ClientPlugin(client);

// If we're running remotely, set up the remote song host.
// If this condition returns false, that indicates that
// the two sides of the transaction are happening on the
// same process.
if (!(client instanceof PlayerHaterClient)) {
SongHost.setRemote(client);
}

if (nowPlaying() != null) {
mClient.onSongChanged(nowPlaying());
Expand Down Expand Up @@ -99,13 +107,6 @@ public void setClient(IPlayerHaterClient client) {

getPluginCollection().add(mClient);

// If we're running remotely, set up the remote song host.
// If this condition returns false, that indicates that
// the two sides of the transaction are happening on the
// same process.
if (!(client instanceof PlayerHaterClient)) {
SongHost.setRemote(client);
}
} else {
mClient = null;
SongHost.clear();
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/org/prx/playerhater/songs/SongHost.java
Expand Up @@ -64,6 +64,9 @@ public static SparseArray<Bundle> localSongs() {
}

static Remote remote() {
if (sRemote == null) {
return new NullRemote();
}
return sRemote;
}

Expand Down Expand Up @@ -205,4 +208,44 @@ public String getSongAlbumTitle(int tag) throws RemoteException {
return mServer.getSongAlbumTitle(tag);
}
}

private static class NullRemote implements Remote {

@Override
public Uri getSongAlbumArt(int tag) throws RemoteException {
// TODO Auto-generated method stub
return null;
}

@Override
public Uri getSongUri(int tag) throws RemoteException {
// TODO Auto-generated method stub
return null;
}

@Override
public String getSongAlbumTitle(int tag) throws RemoteException {
// TODO Auto-generated method stub
return null;
}

@Override
public String getSongTitle(int tag) throws RemoteException {
// TODO Auto-generated method stub
return null;
}

@Override
public String getSongArtist(int tag) throws RemoteException {
// TODO Auto-generated method stub
return null;
}

@Override
public Bundle getSongExtra(int tag) throws RemoteException {
// TODO Auto-generated method stub
return null;
}

}
}

0 comments on commit 44198cf

Please sign in to comment.