Full screen for videos
This commit is contained in:
parent
b720cbf67f
commit
4ba0c99efd
|
@ -18,13 +18,16 @@ package fr.gouv.etalab.mastodon.activities;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.media.MediaPlayer;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.Toast;
|
||||
import android.widget.VideoView;
|
||||
|
||||
|
@ -37,11 +40,15 @@ import java.util.Objects;
|
|||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrievePeertubeSingleAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Peertube;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Results;
|
||||
import fr.gouv.etalab.mastodon.client.TLSSocketFactory;
|
||||
import fr.gouv.etalab.mastodon.helper.FullScreenMediaController;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrievePeertubeInterface;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -49,12 +56,14 @@ import fr.gouv.etalab.mastodon.helper.Helper;
|
|||
* Peertube activity
|
||||
*/
|
||||
|
||||
public class PeertubeActivity extends BaseActivity {
|
||||
public class PeertubeActivity extends BaseActivity implements OnRetrievePeertubeInterface {
|
||||
|
||||
private String url, stream_url;
|
||||
private String url, stream_url, peertubeInstance, videoId;
|
||||
private String peertubeLinkToFetch;
|
||||
private boolean peertubeLink;
|
||||
private FullScreenMediaController.fullscreen fullscreen;
|
||||
private VideoView videoView;
|
||||
private RelativeLayout loader;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -77,43 +86,35 @@ public class PeertubeActivity extends BaseActivity {
|
|||
}
|
||||
|
||||
setContentView(R.layout.activity_peertube);
|
||||
loader = findViewById(R.id.loader);
|
||||
loader.setVisibility(View.VISIBLE);
|
||||
Bundle b = getIntent().getExtras();
|
||||
if(b != null) {
|
||||
peertubeInstance = b.getString("peertube_instance", null);
|
||||
videoId = b.getString("video_id", null);
|
||||
stream_url = b.getString("stream_url", null);
|
||||
peertubeLinkToFetch = b.getString("peertubeLinkToFetch", null);
|
||||
peertubeLink = b.getBoolean("peertubeLink", true);
|
||||
url = b.getString("url", null);
|
||||
}
|
||||
|
||||
|
||||
if( url == null)
|
||||
finish();
|
||||
if( getSupportActionBar() != null)
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
VideoView videoView = findViewById(R.id.media_video);
|
||||
if(fullscreen == FullScreenMediaController.fullscreen.ON){
|
||||
videoView = findViewById(R.id.media_video);
|
||||
new RetrievePeertubeSingleAsyncTask(PeertubeActivity.this, peertubeInstance, videoId, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
/*if(fullscreen == FullScreenMediaController.fullscreen.ON){
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
getSupportActionBar().hide();
|
||||
Log.v(Helper.TAG,"ici");
|
||||
}else{
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
|
||||
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
|
||||
getSupportActionBar().show();
|
||||
}
|
||||
|
||||
Uri uri = Uri.parse(stream_url);
|
||||
try {
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(new TLSSocketFactory());
|
||||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
videoView.setVideoURI(uri);
|
||||
FullScreenMediaController mc = new FullScreenMediaController(PeertubeActivity.this);
|
||||
mc.setAnchorView(videoView);
|
||||
videoView.setMediaController(mc);
|
||||
videoView.start();
|
||||
}*/
|
||||
}
|
||||
|
||||
public void change(){
|
||||
|
@ -200,4 +201,40 @@ public class PeertubeActivity extends BaseActivity {
|
|||
public void setFullscreen(FullScreenMediaController.fullscreen fullscreen) {
|
||||
this.fullscreen = fullscreen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrievePeertube(APIResponse apiResponse) {
|
||||
|
||||
if( apiResponse == null || (apiResponse.getError() != null) || apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0){
|
||||
Toast.makeText(PeertubeActivity.this, R.string.toast_error,Toast.LENGTH_LONG).show();
|
||||
loader.setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
if( apiResponse.getPeertubes().get(0).getStreamURL() == null){
|
||||
Toast.makeText(PeertubeActivity.this, R.string.toast_error,Toast.LENGTH_LONG).show();
|
||||
loader.setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
|
||||
Uri uri = Uri.parse(apiResponse.getPeertubes().get(0).getStreamURL());
|
||||
try {
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(new TLSSocketFactory());
|
||||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
videoView.setVideoURI(uri);
|
||||
FullScreenMediaController mc = new FullScreenMediaController(PeertubeActivity.this);
|
||||
mc.setAnchorView(videoView);
|
||||
videoView.setMediaController(mc);
|
||||
videoView.start();
|
||||
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
|
||||
@Override
|
||||
public void onPrepared(MediaPlayer mp) {
|
||||
loader.setVisibility(View.GONE);
|
||||
mp.start();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/* Copyright 2018 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Mastalab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Mastalab 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 General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
package fr.gouv.etalab.mastodon.asynctasks;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import java.lang.ref.WeakReference;
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrievePeertubeInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Thomas on 15/10/2018.
|
||||
* Retrieves peertube single
|
||||
*/
|
||||
|
||||
public class RetrievePeertubeSingleAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
|
||||
|
||||
private APIResponse apiResponse;
|
||||
private String videoId;
|
||||
private OnRetrievePeertubeInterface listener;
|
||||
private WeakReference<Context> contextReference;
|
||||
private String instanceName;
|
||||
|
||||
|
||||
|
||||
public RetrievePeertubeSingleAsyncTask(Context context, String instanceName, String videoId, OnRetrievePeertubeInterface onRetrievePeertubeInterface){
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.videoId = videoId;
|
||||
this.listener = onRetrievePeertubeInterface;
|
||||
this.instanceName = instanceName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
API api = new API(this.contextReference.get());
|
||||
apiResponse = api.getSinglePeertube(this.instanceName, videoId);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrievePeertube(apiResponse);
|
||||
}
|
||||
}
|
|
@ -637,6 +637,37 @@ public class API {
|
|||
return apiResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves Peertube videos from an instance *synchronously*
|
||||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse getSinglePeertube(String instance, String videoId) {
|
||||
|
||||
|
||||
Peertube peertube = null;
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(String.format("https://"+instance+"/api/v1/videos/%s", videoId), 60, null, null);
|
||||
JSONObject jsonObject = new JSONObject(response);
|
||||
peertube = parseSinglePeertube(jsonObject);
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
List<Peertube> peertubes = new ArrayList<>();
|
||||
peertubes.add(peertube);
|
||||
apiResponse.setPeertubes(peertubes);
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves home timeline for the account *synchronously*
|
||||
* @return APIResponse
|
||||
|
@ -2285,7 +2316,6 @@ public class API {
|
|||
try {
|
||||
int i = 0;
|
||||
while (i < jsonArray.length() ){
|
||||
|
||||
JSONObject resobj = jsonArray.getJSONObject(i);
|
||||
Peertube peertube = parsePeertube(context, resobj);
|
||||
i++;
|
||||
|
@ -2320,6 +2350,33 @@ public class API {
|
|||
return peertube;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse json response for unique how to
|
||||
* @param resobj JSONObject
|
||||
* @return Peertube
|
||||
*/
|
||||
private static Peertube parseSinglePeertube(JSONObject resobj){
|
||||
Peertube peertube = new Peertube();
|
||||
try {
|
||||
peertube.setId(resobj.get("id").toString());
|
||||
peertube.setUuid(resobj.get("uuid").toString());
|
||||
peertube.setName(resobj.get("name").toString());
|
||||
peertube.setDescription(resobj.get("description").toString());
|
||||
peertube.setEmbedPath(resobj.get("embedPath").toString());
|
||||
peertube.setPreviewPath(resobj.get("previewPath").toString());
|
||||
peertube.setThumbnailPath(resobj.get("thumbnailPath").toString());
|
||||
|
||||
JSONArray files = resobj.getJSONArray("files");
|
||||
for(int j = 0 ; j < files.length() ; j++){
|
||||
JSONObject attObj = files.getJSONObject(j);
|
||||
peertube.setStreamURL(attObj.get("fileDownloadUrl").toString());
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return peertube;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse json response for unique how to
|
||||
|
|
|
@ -27,6 +27,7 @@ public class Peertube {
|
|||
private String thumbnailPath;
|
||||
private String previewPath;
|
||||
private String embedPath;
|
||||
private String streamURL;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
|
@ -84,4 +85,11 @@ public class Peertube {
|
|||
this.embedPath = embedPath;
|
||||
}
|
||||
|
||||
public String getStreamURL() {
|
||||
return streamURL;
|
||||
}
|
||||
|
||||
public void setStreamURL(String streamURL) {
|
||||
this.streamURL = streamURL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,9 +117,11 @@ public class PeertubeAdapter extends RecyclerView.Adapter implements OnListActio
|
|||
Matcher matcherLink = link.matcher(finalUrl);
|
||||
if( matcherLink.find()) {
|
||||
String url = matcherLink.group(1) + "/videos/watch/" + matcherLink.group(2);
|
||||
String stream_url = matcherLink.group(1) + "/static/webseed/" + matcherLink.group(2) + "-360.mp4";
|
||||
String stream_url = peertube.getStreamURL();
|
||||
b.putString("peertubeLinkToFetch", url);
|
||||
b.putString("stream_url", stream_url);
|
||||
b.putString("peertube_instance", matcherLink.group(1).replace("https://","").replace("http://",""));
|
||||
b.putString("video_id", matcherLink.group(2));
|
||||
}
|
||||
intent.putExtras(b);
|
||||
context.startActivity(intent);
|
||||
|
|
|
@ -1,4 +1,19 @@
|
|||
package fr.gouv.etalab.mastodon.helper;
|
||||
/* Copyright 2018 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Mastalab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Mastalab 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 General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
|
@ -11,6 +26,10 @@ import android.widget.MediaController;
|
|||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.activities.PeertubeActivity;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 14/10/2018.
|
||||
* FullScreenMediaController. Inspired from the work at http://www.zoftino.com/android-videoview-playing-videos-full-screen
|
||||
*/
|
||||
public class FullScreenMediaController extends MediaController {
|
||||
|
||||
private ImageButton fullScreen;
|
||||
|
@ -37,6 +56,7 @@ public class FullScreenMediaController extends MediaController {
|
|||
LayoutParams.WRAP_CONTENT);
|
||||
params.gravity = Gravity.RIGHT;
|
||||
params.rightMargin = 80;
|
||||
params.topMargin = 22;
|
||||
addView(fullScreen, params);
|
||||
|
||||
if(((PeertubeActivity)getContext()).getFullscreen() == fullscreen.ON){
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/* Copyright 2018 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Mastalab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Mastalab 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 General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
package fr.gouv.etalab.mastodon.interfaces;
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 15/10/2018.
|
||||
* Interface when status have been retrieved
|
||||
*/
|
||||
public interface OnRetrievePeertubeInterface {
|
||||
void onRetrievePeertube(APIResponse apiResponse);
|
||||
}
|
|
@ -23,6 +23,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".activities.PeertubeActivity">
|
||||
|
||||
<VideoView
|
||||
android:id="@+id/media_video"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -32,4 +33,17 @@
|
|||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
<!-- Main Loader -->
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/loader"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
>
|
||||
<ProgressBar
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminate="true" />
|
||||
</RelativeLayout>
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
|
|
Loading…
Reference in New Issue