diff --git a/src/main/java/com/owncloud/android/files/FileMenuFilter.java b/src/main/java/com/owncloud/android/files/FileMenuFilter.java
index 2b0be52c48..6a91d37efc 100644
--- a/src/main/java/com/owncloud/android/files/FileMenuFilter.java
+++ b/src/main/java/com/owncloud/android/files/FileMenuFilter.java
@@ -27,6 +27,7 @@ import android.view.Menu;
import android.view.MenuItem;
import com.owncloud.android.R;
+import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
@@ -345,6 +346,16 @@ public class FileMenuFilter {
toShow.add(R.id.action_download_file);
}
}
+
+ private void filterStream() {
+ // STREAM
+ if (mFiles.isEmpty() || !isSingleFile() || !isSingleMedia() ||
+ !AccountUtils.getServerVersion(mAccount).isMediaStreamingSupported()) {
+ toHide.add(R.id.action_stream_media);
+ } else {
+ toShow.add(R.id.action_stream_media);
+ }
+ }
private boolean anyFileSynchronizing() {
boolean synchronizing = false;
@@ -430,6 +441,11 @@ public class FileMenuFilter {
return isSingleSelection() && MimeTypeUtil.isImage(mFiles.iterator().next());
}
+ private boolean isSingleMedia() {
+ OCFile file = mFiles.iterator().next();
+ return isSingleSelection() && (MimeTypeUtil.isVideo(file) || MimeTypeUtil.isAudio(file));
+ }
+
private boolean allFiles() {
return mFiles != null && !containsFolder();
}
diff --git a/src/main/java/com/owncloud/android/files/StreamMediaFileOperation.java b/src/main/java/com/owncloud/android/files/StreamMediaFileOperation.java
new file mode 100644
index 0000000000..6d573ef272
--- /dev/null
+++ b/src/main/java/com/owncloud/android/files/StreamMediaFileOperation.java
@@ -0,0 +1,90 @@
+/*
+ * Nextcloud Android client application
+ *
+ * @author Tobias Kaminsky
+ * Copyright (C) 2018 Tobias Kaminsky
+ * Copyright (C) 2018 Nextcloud GmbH.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+package com.owncloud.android.files;
+
+import com.owncloud.android.lib.common.OwnCloudClient;
+import com.owncloud.android.lib.common.operations.RemoteOperation;
+import com.owncloud.android.lib.common.operations.RemoteOperationResult;
+import com.owncloud.android.lib.common.utils.Log_OC;
+
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.json.JSONObject;
+
+import java.util.ArrayList;
+
+public class StreamMediaFileOperation extends RemoteOperation {
+ private static final String TAG = StreamMediaFileOperation.class.getSimpleName();
+ private static final int SYNC_READ_TIMEOUT = 40000;
+ private static final int SYNC_CONNECTION_TIMEOUT = 5000;
+ private static final String STREAM_MEDIA_URL = "/ocs/v2.php/apps/dav/api/v1/direct";
+
+ private String fileID;
+
+ // JSON node names
+ private static final String NODE_OCS = "ocs";
+ private static final String NODE_DATA = "data";
+ private static final String NODE_URL = "url";
+ private static final String JSON_FORMAT = "?format=json";
+
+ public StreamMediaFileOperation(String fileID) {
+ this.fileID = fileID;
+ }
+
+ protected RemoteOperationResult run(OwnCloudClient client) {
+ RemoteOperationResult result;
+ PostMethod postMethod = null;
+
+ try {
+ postMethod = new PostMethod(client.getBaseUri() + STREAM_MEDIA_URL + JSON_FORMAT);
+ postMethod.setParameter("fileId", fileID);
+
+ // remote request
+ postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
+
+ int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);
+
+ if (status == HttpStatus.SC_OK) {
+ String response = postMethod.getResponseBodyAsString();
+
+ // Parse the response
+ JSONObject respJSON = new JSONObject(response);
+ String url = (String) respJSON.getJSONObject(NODE_OCS).getJSONObject(NODE_DATA).get(NODE_URL);
+
+ result = new RemoteOperationResult(true, postMethod);
+ ArrayList