Changed renderer handling.
This commit is contained in:
parent
d8660afaeb
commit
e8ce9eb70a
3 changed files with 89 additions and 55 deletions
|
@ -6,5 +6,6 @@
|
||||||
<string name="title_server">Server</string>
|
<string name="title_server">Server</string>
|
||||||
<string name="play">Play</string>
|
<string name="play">Play</string>
|
||||||
<string name="pause">Pause</string>
|
<string name="pause">Pause</string>
|
||||||
|
<string name="exit_renderer">Do you really want to exit the renderer? Playback will be stopped.</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -140,7 +140,7 @@ public class MainActivity extends SherlockFragmentActivity implements
|
||||||
*/
|
*/
|
||||||
public void play(Item[] playlist, int start) {
|
public void play(Item[] playlist, int start) {
|
||||||
getSupportActionBar().selectTab(getSupportActionBar().getTabAt(0));
|
getSupportActionBar().selectTab(getSupportActionBar().getTabAt(0));
|
||||||
mRendererFragment.play(playlist, start);
|
mRendererFragment.setPlaylist(playlist, start);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,10 @@ import org.teleal.cling.support.avtransport.lastchange.AVTransportVariable;
|
||||||
import org.teleal.cling.support.lastchange.LastChange;
|
import org.teleal.cling.support.lastchange.LastChange;
|
||||||
import org.teleal.cling.support.model.item.Item;
|
import org.teleal.cling.support.model.item.Item;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -229,20 +231,24 @@ public class RendererFragment extends Fragment implements
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plays the URIs in playlist to the current renderer, or caches parameters
|
* Sets the new playlist and starts playing it (if a renderer is selected).
|
||||||
* until a renderer is selected.
|
|
||||||
*
|
|
||||||
* @param playlist Array of URIs to play.
|
|
||||||
* @param start Index of the URI which should be played first.
|
|
||||||
*/
|
*/
|
||||||
public void play(Item[] playlist, final int start) {
|
public void setPlaylist(Item[] playlist, int start) {
|
||||||
mPlaylist = playlist;
|
mPlaylist = playlist;
|
||||||
|
playTrack(start);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plays the specified track in the current playlist, caches value if no
|
||||||
|
* renderer is selected.
|
||||||
|
*/
|
||||||
|
private void playTrack(int track) {
|
||||||
if (mCurrentRenderer != null) {
|
if (mCurrentRenderer != null) {
|
||||||
mListView.setAdapter(mPlaylistAdapter);
|
mListView.setAdapter(mPlaylistAdapter);
|
||||||
final Service<?, ?> service = mCurrentRenderer.findService(
|
final Service<?, ?> service = mCurrentRenderer.findService(
|
||||||
new ServiceType("schemas-upnp-org", "AVTransport"));
|
new ServiceType("schemas-upnp-org", "AVTransport"));
|
||||||
mUpnpService.getControlPoint().execute(new SetAVTransportURI(service,
|
mUpnpService.getControlPoint().execute(new SetAVTransportURI(service,
|
||||||
playlist[start].getFirstResource().getValue(), "NO METADATA") {
|
mPlaylist[track].getFirstResource().getValue(), "NO METADATA") {
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Override
|
@Override
|
||||||
public void failure(ActionInvocation invocation,
|
public void failure(ActionInvocation invocation,
|
||||||
|
@ -253,21 +259,14 @@ public class RendererFragment extends Fragment implements
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Override
|
@Override
|
||||||
public void success(ActionInvocation invocation) {
|
public void success(ActionInvocation invocation) {
|
||||||
mUpnpService.getControlPoint().execute(new Play(service) {
|
play();
|
||||||
|
|
||||||
@Override
|
|
||||||
public void failure(ActionInvocation invocation,
|
|
||||||
UpnpResponse operation, String defaultMsg) {
|
|
||||||
Log.w(TAG, "Playback failed: " + defaultMsg);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Toast.makeText(getActivity(), "Please select a renderer.",
|
Toast.makeText(getActivity(), "Please select a renderer.",
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
mCachedStart = start;
|
mCachedStart = track;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +275,7 @@ public class RendererFragment extends Fragment implements
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
|
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
|
||||||
if (mCurrentRenderer == null) {
|
if (mListView.getAdapter() == mRendererAdapter) {
|
||||||
mCurrentRenderer = mRendererAdapter.getItem(position);
|
mCurrentRenderer = mRendererAdapter.getItem(position);
|
||||||
Service<?, ?> service = mCurrentRenderer.findService(
|
Service<?, ?> service = mCurrentRenderer.findService(
|
||||||
new ServiceType("schemas-upnp-org", "AVTransport"));
|
new ServiceType("schemas-upnp-org", "AVTransport"));
|
||||||
|
@ -312,7 +311,6 @@ public class RendererFragment extends Fragment implements
|
||||||
public void run() {
|
public void run() {
|
||||||
mPlayPause.setText(R.string.pause);
|
mPlayPause.setText(R.string.pause);
|
||||||
mPlaying = true;
|
mPlaying = true;
|
||||||
Log.d(TAG, "play");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
@ -325,7 +323,6 @@ public class RendererFragment extends Fragment implements
|
||||||
public void run() {
|
public void run() {
|
||||||
mPlayPause.setText(R.string.play);
|
mPlayPause.setText(R.string.play);
|
||||||
mPlaying = false;
|
mPlaying = false;
|
||||||
Log.d(TAG, "stop");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
@ -351,7 +348,7 @@ public class RendererFragment extends Fragment implements
|
||||||
};
|
};
|
||||||
mUpnpService.getControlPoint().execute(mSubscriptionCallback);
|
mUpnpService.getControlPoint().execute(mSubscriptionCallback);
|
||||||
if (mCachedStart != -1) {
|
if (mCachedStart != -1) {
|
||||||
play(mPlaylist, mCachedStart);
|
setPlaylist(mPlaylist, mCachedStart);
|
||||||
mCachedStart = -1;
|
mCachedStart = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -365,15 +362,36 @@ public class RendererFragment extends Fragment implements
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onBackPressed() {
|
public boolean onBackPressed() {
|
||||||
if (mCurrentRenderer != null) {
|
if (mListView.getAdapter() == mPlaylistAdapter) {
|
||||||
|
if (mPlaying) {
|
||||||
|
new AlertDialog.Builder(getActivity())
|
||||||
|
.setMessage(R.string.exit_renderer)
|
||||||
|
.setPositiveButton(android.R.string.yes,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog,
|
||||||
|
int which) {
|
||||||
|
pause();
|
||||||
|
exitPlaylistMode();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton(android.R.string.no, null)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
exitPlaylistMode();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void exitPlaylistMode() {
|
||||||
mCurrentRenderer = null;
|
mCurrentRenderer = null;
|
||||||
mSubscriptionCallback.end();
|
mSubscriptionCallback.end();
|
||||||
|
|
||||||
mListView.setAdapter(mRendererAdapter);
|
mListView.setAdapter(mRendererAdapter);
|
||||||
mPlayPause.setVisibility(View.GONE);
|
mPlayPause.setVisibility(View.GONE);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -383,9 +401,19 @@ public class RendererFragment extends Fragment implements
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
switch (v.getId()) {
|
switch (v.getId()) {
|
||||||
case R.id.playpause:
|
case R.id.playpause:
|
||||||
|
if (mPlaying)
|
||||||
|
pause();
|
||||||
|
else
|
||||||
|
play();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends 'pause' signal to current renderer.
|
||||||
|
*/
|
||||||
|
private void pause() {
|
||||||
final Service<?, ?> service = mCurrentRenderer.findService(
|
final Service<?, ?> service = mCurrentRenderer.findService(
|
||||||
new ServiceType("schemas-upnp-org", "AVTransport"));
|
new ServiceType("schemas-upnp-org", "AVTransport"));
|
||||||
if (mPlaying) {
|
|
||||||
mUpnpService.getControlPoint().execute(new Stop(service) {
|
mUpnpService.getControlPoint().execute(new Stop(service) {
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
|
@ -404,7 +432,14 @@ public class RendererFragment extends Fragment implements
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends 'play' signal to current renderer.
|
||||||
|
*/
|
||||||
|
private void play() {
|
||||||
|
final Service<?, ?> service = mCurrentRenderer.findService(
|
||||||
|
new ServiceType("schemas-upnp-org", "AVTransport"));
|
||||||
mUpnpService.getControlPoint().execute(new Play(service) {
|
mUpnpService.getControlPoint().execute(new Play(service) {
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
|
@ -415,7 +450,5 @@ public class RendererFragment extends Fragment implements
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue