-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Media streaming with NC14 endpoint #2524
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b8bceee
media streaming with NC14 endpoint
tobiasKaminsky f703911
remove cast
tobiasKaminsky 5b1a011
Changes due to CR
tobiasKaminsky e11f00a
changes due to rebase
tobiasKaminsky 8869e4c
remove unneeded string
tobiasKaminsky c29ccf6
Changes due to Codacy
tobiasKaminsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/main/java/com/owncloud/android/files/StreamMediaFileOperation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| /* | ||
| * 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 <http://www.gnu.org/licenses/>. | ||
| */ | ||
| 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 = respJSON.getJSONObject(NODE_OCS).getJSONObject(NODE_DATA).getString(NODE_URL); | ||
|
|
||
| result = new RemoteOperationResult(true, postMethod); | ||
| ArrayList<Object> urlArray = new ArrayList<>(); | ||
| urlArray.add(url); | ||
| result.setData(urlArray); | ||
| } else { | ||
| result = new RemoteOperationResult(false, postMethod); | ||
| client.exhaustResponse(postMethod.getResponseBodyAsStream()); | ||
| } | ||
| } catch (Exception e) { | ||
| result = new RemoteOperationResult(e); | ||
| Log_OC.e(TAG, "Get stream url for file with id " + fileID + " failed: " + result.getLogMessage(), | ||
| result.getException()); | ||
| } finally { | ||
| if (postMethod != null) { | ||
| postMethod.releaseConnection(); | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there no other way but an AsyncTask? I thought we got rid of this ages ago :P