Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend local webserver to provide files from internal/external storage via directory structure #70

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
buildscript {
repositories {
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
apply plugin: 'com.android.application'

repositories {
maven { url "file:/opt/android-studio/gradle/m2repository" }
mavenCentral()
mavenLocal()
maven {
url 'http://4thline.org/m2'
}
google()
}

dependencies {
Expand All @@ -27,18 +30,19 @@ dependencies {
compile group: 'org.eclipse.jetty', name: 'jetty-servlet', version:'8.1.18.v20150929'
compile group: 'org.eclipse.jetty', name: 'jetty-client', version:'8.1.18.v20150929'
compile group: 'org.slf4j', name: 'slf4j-jdk14', version:'1.7.14'
compile group: 'org.apache.tika', name: 'tika-core', version: '1.8'

compile('de.psdev.licensesdialog:licensesdialog:1.8.1') {
exclude module: 'support-v4'
}
}

android {
compileSdkVersion 26
buildToolsVersion "26"
compileSdkVersion 28
// buildToolsVersion '27.0.3'

defaultConfig {
minSdkVersion 14
minSdkVersion 24
targetSdkVersion 26
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Jul 09 16:35:31 IST 2017
#Fri May 04 17:48:57 CEST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
14 changes: 13 additions & 1 deletion src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,23 @@
android:theme="@style/AppTheme" >
<activity
android:name="org.droidupnp.Main"
android:label="@string/app_name" >
android:label="@string/app_name"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:label="@string/play_with_droidupnp">
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="video/*" />
<data android:scheme="file" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="*" />
</intent-filter>
</activity>
<activity
android:name="org.droidupnp.view.SettingsActivity"
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/org/droidupnp/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
Expand Down Expand Up @@ -117,6 +118,14 @@ protected void onCreate(Bundle savedInstanceState)
}
}

@Override
public void onStart()
{
Log.v(TAG, "Start activity");
super.onStart();
handleIntent(getIntent());
}

@Override
public void onResume()
{
Expand Down Expand Up @@ -192,6 +201,46 @@ public void onBackPressed()
super.onBackPressed();
}

@Override
protected void onNewIntent(Intent intent) {
Log.v(TAG, "New intent");
super.onNewIntent(intent);
setIntent(intent);
}

private void handleIntent(Intent intent) {
final String action = intent.getAction();
String videoUri;
if (action == null) {
Log.d(TAG, "Intent already handled");
return;
} else if (action.equals(Intent.ACTION_SEND)) {
videoUri = intent.getStringExtra(Intent.EXTRA_TEXT);
if (videoUri == null) {
videoUri = intent.getStringExtra(Intent.EXTRA_STREAM);
}
} else if (action.equals(Intent.ACTION_VIEW)) {
videoUri = intent.getDataString();
} else if (action.equals(Intent.ACTION_MAIN)) {
Log.d(TAG, "Nothing to do for main intent");
return;
} else {
Log.e(TAG, "Received unhandled intent: " + action);
return;
}
if (videoUri == null) {
Log.e(TAG, "Received intent " + action + " without URI");
return;
}
Log.i(TAG, "Received intent " + action + " for URI " + videoUri);
String mimeType = intent.getType();
if (!mimeType.equals("video/*")) {
Log.w(TAG,"Received intent " + action + " for unknown mime type " + mimeType);
}
upnpServiceController.playOnNextSelectedRenderer(Uri.parse(videoUri));
intent.setAction(null);
}

private static InetAddress getLocalIpAdressFromIntf(String intfName)
{
try
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/org/droidupnp/controller/cling/RendererCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.fourthline.cling.support.renderingcontrol.callback.SetMute;
import org.fourthline.cling.support.renderingcontrol.callback.SetVolume;

import android.net.Uri;
import android.util.Log;

@SuppressWarnings("rawtypes")
Expand Down Expand Up @@ -326,7 +327,18 @@ else if (upnpItem instanceof TextItem)
"object.item." + type);

Log.i(TAG, "TrackMetadata : "+trackMetadata.toString());
playUri(item.getURI(), trackMetadata);
}

@Override
public void launchUri(Uri uri) {
final TrackMetadata trackMetadata = new TrackMetadata(uri.toString(), uri.getLastPathSegment(),
"", "", "", uri.toString(), "object.item.videoItem");
Log.i(TAG, "TrackMetadata : "+trackMetadata.toString());
playUri(uri.toString(), trackMetadata);
}

private void playUri(final String uri, final TrackMetadata trackMetadata) {
// Stop playback before setting URI
controlPoint.execute(new Stop(getAVTransportService()) {
@Override
Expand All @@ -345,10 +357,9 @@ public void failure(ActionInvocation arg0, UpnpResponse arg1, String arg2)

public void callback()
{
setURI(item.getURI(), trackMetadata);
setURI(uri, trackMetadata);
}
});

}

// Update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,34 @@

import org.droidupnp.model.cling.UpnpService;
import org.droidupnp.model.cling.UpnpServiceController;
import org.droidupnp.model.upnp.IDeviceDiscoveryObserver;
import org.droidupnp.model.upnp.IUpnpDevice;
import org.fourthline.cling.model.meta.LocalDevice;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;

public class ServiceController extends UpnpServiceController
public class ServiceController extends UpnpServiceController implements IDeviceDiscoveryObserver
{
private static final String TAG = "Cling.ServiceController";
protected static final String LAST_RENDERER_DEVICE = "last_renderer_device_uid";
protected static final String LAST_CONTENT_DEVICE = "last_content_device_uid";

private final ServiceListener upnpServiceListener;
private Activity activity = null;
protected SharedPreferences sharedPref;

public ServiceController(Context ctx)
{
super();
upnpServiceListener = new ServiceListener(ctx);
sharedPref = PreferenceManager.getDefaultSharedPreferences(ctx);
getRendererDiscovery().addObserver(this);
getContentDirectoryDiscovery().addObserver(this);
}

@Override
Expand Down Expand Up @@ -83,4 +93,31 @@ public void removeDevice(LocalDevice localDevice) {
upnpServiceListener.getUpnpService().getRegistry().removeDevice(localDevice);
}

@Override
public void setSelectedRenderer(IUpnpDevice renderer, boolean force) {
super.setSelectedRenderer(renderer, force);
if (renderer != null) {
sharedPref.edit().putString(LAST_RENDERER_DEVICE, renderer.getUID()).apply();
}
}

@Override
public void setSelectedContentDirectory(IUpnpDevice contentDirectory, boolean force) {
super.setSelectedContentDirectory(contentDirectory, force);
if (contentDirectory != null) {
sharedPref.edit().putString(LAST_CONTENT_DEVICE, contentDirectory.getUID()).apply();
}
}

@Override
public void addedDevice(IUpnpDevice device) {
if (device.getUID().equals(sharedPref.getString(LAST_RENDERER_DEVICE, ""))) {
setSelectedRenderer(device, false);
} else if (device.getUID().equals(sharedPref.getString(LAST_CONTENT_DEVICE, ""))) {
setSelectedContentDirectory(device, false);
}
}

@Override
public void removedDevice(IUpnpDevice device) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.droidupnp.view.SettingsActivity;
import org.fourthline.cling.android.AndroidUpnpService;
import org.fourthline.cling.model.ValidationException;
import org.fourthline.cling.model.message.header.STAllHeader;
import org.fourthline.cling.model.meta.Device;

import android.content.ComponentName;
Expand Down Expand Up @@ -66,7 +67,7 @@ public ServiceListener(Context ctx)
@Override
public void refresh()
{
upnpService.getControlPoint().search();
upnpService.getControlPoint().search(new STAllHeader());
}

@Override
Expand Down Expand Up @@ -157,7 +158,7 @@ else if(mediaServer != null)
}

// Search asynchronously for all devices, they will respond soon
upnpService.getControlPoint().search();
upnpService.getControlPoint().search(new STAllHeader());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.fourthline.cling.model.meta.LocalDevice;

import android.app.Activity;
import android.net.Uri;

public interface IUpnpServiceController {
public void setSelectedRenderer(IUpnpDevice renderer);
Expand Down Expand Up @@ -65,4 +66,6 @@ public interface IUpnpServiceController {
public void addDevice(LocalDevice localDevice);
public void removeDevice(LocalDevice localDevice);

// Play track on next selected renderer
public void playOnNextSelectedRenderer(Uri uri);
}
25 changes: 25 additions & 0 deletions src/main/java/org/droidupnp/model/cling/UpnpServiceController.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@

import java.util.Observer;

import org.droidupnp.Main;
import org.droidupnp.controller.upnp.IUpnpServiceController;
import org.droidupnp.model.CObservable;
import org.droidupnp.model.upnp.ContentDirectoryDiscovery;
import org.droidupnp.model.upnp.IRendererCommand;
import org.droidupnp.model.upnp.IUpnpDevice;
import org.droidupnp.model.upnp.RendererDiscovery;

import android.app.Activity;
import android.net.Uri;
import android.util.Log;

public abstract class UpnpServiceController implements IUpnpServiceController {
Expand All @@ -43,6 +46,8 @@ public abstract class UpnpServiceController implements IUpnpServiceController {
private final ContentDirectoryDiscovery contentDirectoryDiscovery;
private final RendererDiscovery rendererDiscovery;

private Uri playOnNextSelectedRendererUri;

@Override
public ContentDirectoryDiscovery getContentDirectoryDiscovery()
{
Expand All @@ -62,6 +67,8 @@ protected UpnpServiceController()

contentDirectoryDiscovery = new ContentDirectoryDiscovery(getServiceListener());
rendererDiscovery = new RendererDiscovery(getServiceListener());

playOnNextSelectedRendererUri = null;
}

@Override
Expand All @@ -79,6 +86,13 @@ public void setSelectedRenderer(IUpnpDevice renderer, boolean force)

this.renderer = renderer;
rendererObservable.notifyAllObservers();

// Play URI passed via intent
if (renderer != null && playOnNextSelectedRendererUri != null) {
playOnNextSelectedRenderer(playOnNextSelectedRendererUri);
playOnNextSelectedRendererUri = null;
}
Log.d(TAG,"playOnNextSelectedRendererUri = " + playOnNextSelectedRendererUri);
}

@Override
Expand Down Expand Up @@ -152,4 +166,15 @@ public void resume(Activity activity)
contentDirectoryDiscovery.resume(getServiceListener());
}

@Override
public void playOnNextSelectedRenderer(Uri uri) {
IRendererCommand rendererCommand = Main.factory.createRendererCommand(Main.factory.createRendererState());
if (renderer != null && rendererCommand != null) {
Log.d(TAG, "Play URI " + uri + " immediately");
rendererCommand.launchUri(uri);
} else {
Log.d(TAG, "Play URI " + uri + " when renderer becomes available");
playOnNextSelectedRendererUri = uri;
}
}
}
Loading