aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-11-01 13:12:56 -0700
committerScott Jackson <daneren2005@gmail.com>2014-11-01 13:12:56 -0700
commit14b1c6b67195af12b3905dd28a227a318d678825 (patch)
treecd4e26d4c46cfbf4f79db5c852a727c6269982d7
parent0164ea01c1e0a10a94aa0476761cd20571af5db5 (diff)
downloaddsub-14b1c6b67195af12b3905dd28a227a318d678825.tar.gz
dsub-14b1c6b67195af12b3905dd28a227a318d678825.tar.bz2
dsub-14b1c6b67195af12b3905dd28a227a318d678825.zip
More work on discovering and adding DLNA devices
-rw-r--r--AndroidManifest.xml2
-rw-r--r--libs/cling-core-2.0-alpha3.jarbin0 -> 683382 bytes
-rw-r--r--src/github/daneren2005/dsub/provider/DLNARouteProvider.java99
-rw-r--r--src/github/daneren2005/dsub/util/MediaRouteManager.java7
4 files changed, 108 insertions, 0 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 755b2d21..ae37b51a 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -85,6 +85,8 @@
<service android:name=".service.DownloadService"
android:label="Subsonic Download Service"/>
+ <service android:name="org.teleal.cling.android.AndroidUpnpServiceImpl"/>
+
<service android:name="github.daneren2005.dsub.service.sync.AuthenticatorService">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator"/>
diff --git a/libs/cling-core-2.0-alpha3.jar b/libs/cling-core-2.0-alpha3.jar
new file mode 100644
index 00000000..41bca580
--- /dev/null
+++ b/libs/cling-core-2.0-alpha3.jar
Binary files differ
diff --git a/src/github/daneren2005/dsub/provider/DLNARouteProvider.java b/src/github/daneren2005/dsub/provider/DLNARouteProvider.java
index edde4d3e..11c29d28 100644
--- a/src/github/daneren2005/dsub/provider/DLNARouteProvider.java
+++ b/src/github/daneren2005/dsub/provider/DLNARouteProvider.java
@@ -18,16 +18,28 @@
*/
package github.daneren2005.dsub.provider;
+import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.ServiceConnection;
import android.media.AudioManager;
import android.media.MediaRouter;
+import android.os.IBinder;
import android.support.v7.media.MediaControlIntent;
import android.support.v7.media.MediaRouteDescriptor;
import android.support.v7.media.MediaRouteDiscoveryRequest;
import android.support.v7.media.MediaRouteProvider;
import android.support.v7.media.MediaRouteProviderDescriptor;
+import android.util.Log;
+
+import org.fourthline.cling.android.AndroidUpnpService;
+import org.fourthline.cling.android.AndroidUpnpServiceImpl;
+import org.fourthline.cling.model.meta.Device;
+import org.fourthline.cling.model.meta.LocalDevice;
+import org.fourthline.cling.model.meta.RemoteDevice;
+import org.fourthline.cling.registry.Registry;
+import org.fourthline.cling.registry.RegistryListener;
import java.util.HashMap;
import java.util.Map;
@@ -41,16 +53,82 @@ import github.daneren2005.dsub.service.RemoteController;
* Created by Scott on 11/28/13.
*/
public class DLNARouteProvider extends MediaRouteProvider {
+ private static final String TAG = DLNARouteProvider.class.getSimpleName();
public static final String CATEGORY_DLNA = "github.daneren2005.dsub.DLNA";
private DownloadService downloadService;
private RemoteController controller;
private HashMap<String, DLNADevice> devices = new HashMap<String, DLNADevice>();
+ private AndroidUpnpService dlnaService;
+ private ServiceConnection dlnaServiceConnection;
public DLNARouteProvider(Context context) {
super(context);
this.downloadService = (DownloadService) context;
+ dlnaServiceConnection = new ServiceConnection() {
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ dlnaService = (AndroidUpnpService) service;
+ dlnaService.getRegistry().addListener(new RegistryListener() {
+ @Override
+ public void remoteDeviceDiscoveryStarted(Registry registry, RemoteDevice remoteDevice) {
+
+ }
+
+ @Override
+ public void remoteDeviceDiscoveryFailed(Registry registry, RemoteDevice remoteDevice, Exception e) {
+
+ }
+
+ @Override
+ public void remoteDeviceAdded(Registry registry, RemoteDevice remoteDevice) {
+ deviceAdded(remoteDevice);
+ }
+
+ @Override
+ public void remoteDeviceUpdated(Registry registry, RemoteDevice remoteDevice) {
+ deviceAdded(remoteDevice);
+ }
+
+ @Override
+ public void remoteDeviceRemoved(Registry registry, RemoteDevice remoteDevice) {
+ deviceRemoved(remoteDevice);
+ }
+
+ @Override
+ public void localDeviceAdded(Registry registry, LocalDevice localDevice) {
+ deviceAdded(localDevice);
+ }
+
+ @Override
+ public void localDeviceRemoved(Registry registry, LocalDevice localDevice) {
+ deviceRemoved(localDevice);
+ }
+
+ @Override
+ public void beforeShutdown(Registry registry) {
+
+ }
+
+ @Override
+ public void afterShutdown() {
+
+ }
+ });
+
+ for (Device<?, ?, ?> device : dlnaService.getControlPoint().getRegistry().getDevices()) {
+ deviceAdded(device);
+ }
+ dlnaService.getControlPoint().search();
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ dlnaService = null;
+ }
+ };
+ context.bindService(new Intent(context, AndroidUpnpServiceImpl.class), dlnaServiceConnection,Context.BIND_AUTO_CREATE);
}
private void broadcastDescriptors() {
@@ -82,6 +160,7 @@ public class DLNARouteProvider extends MediaRouteProvider {
setDescriptor(providerBuilder.build());
}
+ @Override
public void onDiscoveryRequestChanged(MediaRouteDiscoveryRequest request) {
if (request != null && request.isActiveScan()) {
@@ -93,6 +172,26 @@ public class DLNARouteProvider extends MediaRouteProvider {
return new DLNARouteController(downloadService);
}
+ private void deviceAdded(Device device) {
+ if(device.getType().getType().equals("MediaRenderer") && device instanceof RemoteDevice) {
+ String id = device.getIdentity().getUdn().toString();
+ String name = device.getDetails().getFriendlyName();
+ String displayName = device.getDisplayString();
+ Log.d(TAG, displayName);
+
+ DLNADevice newDevice = new DLNADevice(id, name, displayName, 0, 10);
+ devices.put(id, newDevice);
+ broadcastDescriptors();
+ }
+ }
+ private void deviceRemoved(Device device) {
+ if(device.getType().getType().equals("MediaRenderer") && device instanceof RemoteDevice) {
+ String id = device.getIdentity().getUdn().toString();
+ devices.remove(id);
+ broadcastDescriptors();
+ }
+ }
+
private class DLNARouteController extends RouteController {
private DownloadService downloadService;
diff --git a/src/github/daneren2005/dsub/util/MediaRouteManager.java b/src/github/daneren2005/dsub/util/MediaRouteManager.java
index 347b0376..e356a1b6 100644
--- a/src/github/daneren2005/dsub/util/MediaRouteManager.java
+++ b/src/github/daneren2005/dsub/util/MediaRouteManager.java
@@ -27,6 +27,7 @@ import java.util.ArrayList;
import java.util.List;
import github.daneren2005.dsub.domain.RemoteControlState;
+import github.daneren2005.dsub.provider.DLNARouteProvider;
import github.daneren2005.dsub.provider.JukeboxRouteProvider;
import github.daneren2005.dsub.service.DownloadService;
import github.daneren2005.dsub.service.RemoteController;
@@ -145,6 +146,11 @@ public class MediaRouteManager extends MediaRouter.Callback {
router.addProvider(jukeboxProvider);
providers.add(jukeboxProvider);
offlineProviders.add(jukeboxProvider);
+
+ DLNARouteProvider dlnaProvider = new DLNARouteProvider(downloadService);
+ router.addProvider(dlnaProvider);
+ providers.add(dlnaProvider);
+ offlineProviders.add(dlnaProvider);
}
public void removeOfflineProviders() {
for(MediaRouteProvider provider: offlineProviders) {
@@ -165,6 +171,7 @@ public class MediaRouteManager extends MediaRouter.Callback {
if(castAvailable) {
builder.addControlCategory(CastCompat.getCastControlCategory());
}
+ builder.addControlCategory(DLNARouteProvider.CATEGORY_DLNA);
selector = builder.build();
}
}