Added device playlist to renderer fragment.
This commit is contained in:
parent
43df4e21db
commit
2d38870dfe
7 changed files with 80 additions and 20 deletions
|
@ -29,10 +29,21 @@
|
|||
android:layout_height="wrap_content" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/playpause"
|
||||
android:id="@+id/previous"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="playPauseClicked" />
|
||||
android:text="@string/previous" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/playpause"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/next"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/next" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
@ -7,5 +7,7 @@
|
|||
<string name="play">Play</string>
|
||||
<string name="pause">Pause</string>
|
||||
<string name="exit_renderer">Do you really want to exit the renderer? Playback will be stopped.</string>
|
||||
<string name="previous">Previous</string>
|
||||
<string name="next">Next</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.github.nutomic.controldlna;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.teleal.cling.model.meta.Device;
|
||||
import org.teleal.cling.model.meta.LocalDevice;
|
||||
import org.teleal.cling.model.meta.RemoteDevice;
|
||||
|
@ -121,4 +123,13 @@ public class DeviceArrayAdapter extends ArrayAdapter<Device<?, ?, ?>>
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Not implemented on lower API levels.
|
||||
*/
|
||||
@Override
|
||||
public void addAll(Collection<? extends Device<?, ?, ?>> collection) {
|
||||
for (Device<?, ?, ?> d : collection)
|
||||
add(d);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.github.nutomic.controldlna;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.teleal.cling.support.model.DIDLObject;
|
||||
|
||||
import android.content.Context;
|
||||
|
@ -27,4 +29,13 @@ public class FileArrayAdapter extends ArrayAdapter<DIDLObject> {
|
|||
return convertView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not implemented on lower API levels.
|
||||
*/
|
||||
@Override
|
||||
public void addAll(Collection<? extends DIDLObject> collection) {
|
||||
for (DIDLObject d : collection)
|
||||
add(d);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.github.nutomic.controldlna;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.teleal.cling.support.model.item.Item;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
@ -138,7 +140,7 @@ public class MainActivity extends SherlockFragmentActivity implements
|
|||
/**
|
||||
* Utility function to call RendererFragment.play from ServerFragment.
|
||||
*/
|
||||
public void play(Item[] playlist, int start) {
|
||||
public void play(List<Item> playlist, int start) {
|
||||
getSupportActionBar().selectTab(getSupportActionBar().getTabAt(0));
|
||||
mRendererFragment.setPlaylist(playlist, start);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.github.nutomic.controldlna;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.teleal.cling.android.AndroidUpnpService;
|
||||
|
@ -72,7 +74,9 @@ public class RendererFragment extends Fragment implements
|
|||
|
||||
private boolean mPlaying = false;
|
||||
|
||||
private Item[] mPlaylist;
|
||||
private int mCurrentTrack;
|
||||
|
||||
private List<Item> mPlaylist;
|
||||
|
||||
/**
|
||||
* ListView adapter of media renderers.
|
||||
|
@ -103,14 +107,14 @@ public class RendererFragment extends Fragment implements
|
|||
*/
|
||||
private ServiceConnection mServiceConnection= new ServiceConnection() {
|
||||
|
||||
public void onServiceConnected(ComponentName className, IBinder service) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void onServiceConnected(ComponentName className, IBinder service) {
|
||||
mUpnpService = (AndroidUpnpService) service;
|
||||
Log.i(TAG, "Starting device search");
|
||||
mUpnpService.getRegistry().addListener(mRendererAdapter);
|
||||
mUpnpService.getControlPoint().search();
|
||||
for (Device<?, ?, ?> d : mUpnpService
|
||||
.getControlPoint().getRegistry().getDevices())
|
||||
mRendererAdapter.add(d);
|
||||
mRendererAdapter.addAll((Collection<? extends Device<?, ?, ?>>)
|
||||
mUpnpService.getControlPoint().getRegistry().getDevices());
|
||||
}
|
||||
|
||||
public void onServiceDisconnected(ComponentName className) {
|
||||
|
@ -131,6 +135,7 @@ public class RendererFragment extends Fragment implements
|
|||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
mListView = (ListView) getView().findViewById(R.id.listview);
|
||||
mPlaylistAdapter = new FileArrayAdapter(getActivity());
|
||||
mRendererAdapter = new DeviceArrayAdapter(
|
||||
getActivity(), DeviceArrayAdapter.RENDERER);
|
||||
mListView.setAdapter(mRendererAdapter);
|
||||
|
@ -141,6 +146,8 @@ public class RendererFragment extends Fragment implements
|
|||
mPlayPause = (Button) getView().findViewById(R.id.playpause);
|
||||
mPlayPause.setOnClickListener(this);
|
||||
mPlayPause.setText(R.string.play);
|
||||
getView().findViewById(R.id.previous).setOnClickListener(this);
|
||||
getView().findViewById(R.id.next).setOnClickListener(this);
|
||||
|
||||
getActivity().getApplicationContext().bindService(
|
||||
new Intent(getActivity(), AndroidUpnpServiceImpl.class),
|
||||
|
@ -203,8 +210,10 @@ public class RendererFragment extends Fragment implements
|
|||
/**
|
||||
* Sets the new playlist and starts playing it (if a renderer is selected).
|
||||
*/
|
||||
public void setPlaylist(Item[] playlist, int start) {
|
||||
public void setPlaylist(List<Item> playlist, int start) {
|
||||
mPlaylist = playlist;
|
||||
mPlaylistAdapter.clear();
|
||||
mPlaylistAdapter.addAll(playlist);
|
||||
playTrack(start);
|
||||
}
|
||||
|
||||
|
@ -215,11 +224,12 @@ public class RendererFragment extends Fragment implements
|
|||
private void playTrack(int track) {
|
||||
if (mCurrentRenderer != null) {
|
||||
mListView.setAdapter(mPlaylistAdapter);
|
||||
mCurrentTrack = track;
|
||||
final Service<?, ?> service = mCurrentRenderer.findService(
|
||||
new ServiceType("schemas-upnp-org", "AVTransport"));
|
||||
DIDLParser parser = new DIDLParser();
|
||||
DIDLContent didl = new DIDLContent();
|
||||
didl.addItem(mPlaylist[track]);
|
||||
didl.addItem(mPlaylist.get(track));
|
||||
String metadata;
|
||||
try {
|
||||
metadata = parser.generate(didl, true);
|
||||
|
@ -229,7 +239,7 @@ public class RendererFragment extends Fragment implements
|
|||
metadata = "NO METADATA";
|
||||
}
|
||||
mUpnpService.getControlPoint().execute(new SetAVTransportURI(service,
|
||||
mPlaylist[track].getFirstResource().getValue(), metadata) {
|
||||
mPlaylist.get(track).getFirstResource().getValue(), metadata) {
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void failure(ActionInvocation invocation,
|
||||
|
@ -337,6 +347,8 @@ public class RendererFragment extends Fragment implements
|
|||
mListView.setAdapter(mPlaylistAdapter);
|
||||
mControls.setVisibility(View.VISIBLE);
|
||||
}
|
||||
else if (mListView.getAdapter() == mPlaylistAdapter)
|
||||
playTrack(position);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -387,6 +399,15 @@ public class RendererFragment extends Fragment implements
|
|||
pause();
|
||||
else
|
||||
play();
|
||||
break;
|
||||
case R.id.previous:
|
||||
if (mCurrentTrack != 0 && !mPlaylist.isEmpty())
|
||||
playTrack(--mCurrentTrack);
|
||||
break;
|
||||
case R.id.next:
|
||||
if (mPlaylist.size() > mCurrentTrack + 1)
|
||||
playTrack(++mCurrentTrack);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package com.github.nutomic.controldlna;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import org.teleal.cling.android.AndroidUpnpService;
|
||||
|
@ -73,14 +76,14 @@ public class ServerFragment extends ListFragment implements OnBackPressedListene
|
|||
*/
|
||||
private ServiceConnection mServiceConnection= new ServiceConnection() {
|
||||
|
||||
public void onServiceConnected(ComponentName className, IBinder service) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void onServiceConnected(ComponentName className, IBinder service) {
|
||||
mUpnpService = (AndroidUpnpService) service;
|
||||
Log.i(TAG, "Starting device search");
|
||||
mUpnpService.getRegistry().addListener(mServerAdapter);
|
||||
mUpnpService.getControlPoint().search();
|
||||
for (Device<?, ?, ?> d : mUpnpService
|
||||
.getControlPoint().getRegistry().getDevices())
|
||||
mServerAdapter.add(d);
|
||||
mServerAdapter.addAll((Collection<? extends Device<?, ?, ?>>)
|
||||
mUpnpService.getControlPoint().getRegistry().getDevices());
|
||||
}
|
||||
|
||||
public void onServiceDisconnected(ComponentName className) {
|
||||
|
@ -133,11 +136,10 @@ public class ServerFragment extends ListFragment implements OnBackPressedListene
|
|||
getFiles(((Container) mFileAdapter.getItem(position)).getId());
|
||||
}
|
||||
else {
|
||||
Item[] playlist = new Item[mFileAdapter.getCount()];
|
||||
List<Item> playlist = new ArrayList<Item>();
|
||||
for (int i = 0; i < mFileAdapter.getCount(); i++) {
|
||||
if (mFileAdapter.getItem(i) instanceof Item) {
|
||||
playlist[i] = (Item) mFileAdapter.getItem(position);
|
||||
}
|
||||
if (mFileAdapter.getItem(i) instanceof Item)
|
||||
playlist.add((Item) mFileAdapter.getItem(i));
|
||||
}
|
||||
MainActivity activity = (MainActivity) getActivity();
|
||||
activity.play(playlist, position);
|
||||
|
|
Reference in a new issue