summaryrefslogtreecommitdiffstats
path: root/app/src/main/java/fr/gouv/etalab
diff options
context:
space:
mode:
authorstom79 <tschneider.ac@gmail.com>2019-01-05 16:56:11 +0100
committerstom79 <tschneider.ac@gmail.com>2019-01-05 16:56:11 +0100
commitcdcc41ffac4862d51efccf2497dfe0f4df870769 (patch)
treee84b817320ad80031f675b4f97b7a18d2ae01284 /app/src/main/java/fr/gouv/etalab
parent1deed5212ccdc66a39f3ed2610923dfab503138b (diff)
Exoplayer
Diffstat (limited to 'app/src/main/java/fr/gouv/etalab')
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/activities/NotificationReturnSlot.java23
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java139
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Peertube.java9
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/helper/NotificationPanel.java55
4 files changed, 205 insertions, 21 deletions
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/NotificationReturnSlot.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/NotificationReturnSlot.java
new file mode 100644
index 000000000..c93e03e6f
--- /dev/null
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/NotificationReturnSlot.java
@@ -0,0 +1,23 @@
+package fr.gouv.etalab.mastodon.activities;
+
+import android.os.Bundle;
+import android.support.v7.app.AppCompatActivity;
+import android.util.Log;
+
+public class NotificationReturnSlot extends AppCompatActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ // TODO Auto-generated method stub
+ super.onCreate(savedInstanceState);
+ String action = (String) getIntent().getExtras().get("DO");
+ if (action.equals("volume")) {
+ Log.i("NotificationReturnSlot", "volume");
+ //Your code
+ } else if (action.equals("stopNotification")) {
+ //Your code
+ Log.i("NotificationReturnSlot", "stopNotification");
+ }
+ finish();
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java
index e8db0f2fd..77af7a969 100644
--- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java
@@ -24,13 +24,14 @@ import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.database.sqlite.SQLiteDatabase;
+import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
-import android.support.v4.app.ActivityCompat;
+import android.os.Environment;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
@@ -38,6 +39,7 @@ import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.Html;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
@@ -54,6 +56,12 @@ import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;
+import com.github.se_bastiaan.torrentstream.StreamStatus;
+import com.github.se_bastiaan.torrentstream.Torrent;
+import com.github.se_bastiaan.torrentstream.TorrentOptions;
+import com.github.se_bastiaan.torrentstream.TorrentStream;
+import com.github.se_bastiaan.torrentstream.listeners.TorrentListener;
+
import java.lang.ref.WeakReference;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
@@ -79,12 +87,12 @@ import fr.gouv.etalab.mastodon.client.TLSSocketFactory;
import fr.gouv.etalab.mastodon.drawers.StatusListAdapter;
import fr.gouv.etalab.mastodon.helper.FullScreenMediaController;
import fr.gouv.etalab.mastodon.helper.Helper;
+import fr.gouv.etalab.mastodon.helper.NotificationPanel;
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
import fr.gouv.etalab.mastodon.interfaces.OnRetrievePeertubeInterface;
import fr.gouv.etalab.mastodon.sqlite.PeertubeFavoritesDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
-import static fr.gouv.etalab.mastodon.helper.Helper.EXTERNAL_STORAGE_REQUEST_CODE;
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT;
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
import static fr.gouv.etalab.mastodon.helper.Helper.manageDownloads;
@@ -109,6 +117,9 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
private Peertube peertube;
private TextView toolbar_title;
public static String video_id;
+ private NotificationPanel nPanel;
+ private TorrentStream torrentStream;
+ private TorrentListener torrentListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -142,6 +153,9 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
peertube_title = findViewById(R.id.peertube_title);
peertube_information_container = findViewById(R.id.peertube_information_container);
+
+
+
loader.setVisibility(View.VISIBLE);
Bundle b = getIntent().getExtras();
if(b != null) {
@@ -171,6 +185,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
}
}
videoView = findViewById(R.id.media_video);
+
new RetrievePeertubeSingleAsyncTask(PeertubeActivity.this, peertubeInstance, videoId, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@@ -357,7 +372,8 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
});
}
- Uri uri = Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null));
+ //Uri uri = Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null));
+ Uri uri = Uri.parse(apiResponse.getPeertubes().get(0).getTorrentUrl(null));
try {
HttpsURLConnection.setDefaultSSLSocketFactory(new TLSSocketFactory());
} catch (KeyManagementException e) {
@@ -365,29 +381,77 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
- videoView.setVideoURI(uri);
- videoView.getCurrentPosition();
- fullScreenMediaController = new FullScreenMediaController(PeertubeActivity.this, peertube);
- fullScreenMediaController.setPadding(0, 0, 0, (int)Helper.convertDpToPixel(25, PeertubeActivity.this));
- fullScreenMediaController.setAnchorView(videoView);
- videoView.setMediaController(fullScreenMediaController);
- videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
+
+
+ TorrentOptions torrentOptions = new TorrentOptions.Builder()
+ .saveLocation(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS))
+ .removeFilesAfterStop(true)
+ .build();
+ videoView.setZOrderMediaOverlay(true);
+ videoView.setZOrderOnTop(true);
+ videoView.setBackgroundColor(Color.TRANSPARENT);
+ torrentStream = TorrentStream.init(torrentOptions);
+ torrentStream.startStream(apiResponse.getPeertubes().get(0).getTorrentUrl(null));
+ torrentListener = new TorrentListener() {
+ @Override
+ public void onStreamPrepared(Torrent torrent) {
+ Log.v(Helper.TAG,"onStreamPrepared");
+ }
+
+ @Override
+ public void onStreamStarted(Torrent torrent) {
+ Log.v(Helper.TAG,"onStreamStarted");
+ if (mediaPlayer != null)
+ mediaPlayer.start();
+ videoView.start();
+ }
+
+ @Override
+ public void onStreamError(Torrent torrent, Exception e) {
+ Log.v(Helper.TAG,"onStreamError");
+ }
+
+ @Override
+ public void onStreamReady(Torrent torrent) {
+ Log.v(Helper.TAG,"onStreamReady");
+ videoView.setVideoURI(Uri.fromFile(torrent.getVideoFile()));
+ videoView.getCurrentPosition();
+ fullScreenMediaController = new FullScreenMediaController(PeertubeActivity.this, peertube);
+ fullScreenMediaController.setPadding(0, 0, 0, (int) Helper.convertDpToPixel(25, PeertubeActivity.this));
+ fullScreenMediaController.setAnchorView(videoView);
+ videoView.setMediaController(fullScreenMediaController);
+ videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
+ @Override
+ public void onPrepared(MediaPlayer mp) {
+ loader.setVisibility(View.GONE);
+ mediaPlayer = mp;
+ mp.start();
+ }
+ });
+ videoView.start();
+ }
+
@Override
- public void onPrepared(MediaPlayer mp) {
+ public void onStreamProgress(Torrent torrent, StreamStatus status) {
+ }
+
+ @Override
+ public void onStreamStopped() {
+ Log.v(Helper.TAG,"onStreamStopped");
loader.setVisibility(View.GONE);
- mediaPlayer = mp;
- mp.start();
+ if (mediaPlayer != null)
+ mediaPlayer.pause();
+ videoView.pause();
}
- });
+ };
+ torrentStream.addListener(torrentListener);
- videoView.start();
peertube_download.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(Build.VERSION.SDK_INT >= 23 ){
if (ContextCompat.checkSelfPermission(PeertubeActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(PeertubeActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
- ActivityCompat.requestPermissions(PeertubeActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, EXTERNAL_STORAGE_REQUEST_CODE);
} else {
manageDownloads(PeertubeActivity.this, peertube.getFileDownloadUrl(null));
}
@@ -506,8 +570,10 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
stopPosition = videoView.getCurrentPosition(); //stopPosition is an int
videoView.pause();
}
+ nPanel = new NotificationPanel(PeertubeActivity.this);
}
+
@Override
public void onResume(){
super.onResume();
@@ -516,6 +582,8 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
videoView.resume();
videoView.start();
}
+ if( nPanel != null)
+ nPanel.notificationCancel();
}
public void displayResolution(){
@@ -545,12 +613,41 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
public void onClick(DialogInterface dialog, int which) {
String res = arrayAdapter.getItem(which).substring(0, arrayAdapter.getItem(which).length() - 1);
if( mediaPlayer != null) {
+ loader.setVisibility(View.VISIBLE);
int position = videoView.getCurrentPosition();
- mediaPlayer.stop();
- videoView.setVideoURI(Uri.parse(peertube.getFileUrl(res)));
- fullScreenMediaController.setResolutionVal(res);
- videoView.seekTo(position);
- videoView.start();
+ torrentStream.stopStream();
+ torrentStream.removeListener(torrentListener);
+ torrentStream.startStream(peertube.getTorrentUrl(res));
+ torrentListener = new TorrentListener() {
+ @Override
+ public void onStreamPrepared(Torrent torrent) {
+ loader.setVisibility(View.VISIBLE);
+ }
+ @Override
+ public void onStreamStarted(Torrent torrent) {
+ }
+ @Override
+ public void onStreamError(Torrent torrent, Exception e) {
+ }
+ @Override
+ public void onStreamReady(Torrent torrent) {
+ videoView.setVisibility(View.GONE);
+ videoView.setVisibility(View.VISIBLE);
+ loader.setVisibility(View.GONE);
+ videoView.setVideoURI( Uri.fromFile(torrent.getVideoFile()));
+ fullScreenMediaController.setResolutionVal(res);
+ videoView.seekTo(position);
+ videoView.start();
+ }
+ @Override
+ public void onStreamProgress(Torrent torrent, StreamStatus status) {
+ }
+ @Override
+ public void onStreamStopped() {
+ loader.setVisibility(View.GONE);
+ }
+ };
+ torrentStream.addListener(torrentListener);
}
}
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Peertube.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Peertube.java
index 81fb9fe48..643c0e06d 100644
--- a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Peertube.java
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Peertube.java
@@ -176,6 +176,15 @@ public class Peertube {
}
+ public String getTorrentUrl(String resolution) {
+ if( resolution == null)
+ resolution = this.getResolution().get(0);
+ if(resolution == null)
+ return null;
+ return "https://" + this.host + "/static/torrents/" + getUuid()+ "-" + resolution + ".torrent";
+
+ }
+
public String getTorrentDownloadUrl(String resolution) {
if( resolution == null)
resolution = this.getResolution().get(0);
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/NotificationPanel.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/NotificationPanel.java
new file mode 100644
index 000000000..771138083
--- /dev/null
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/NotificationPanel.java
@@ -0,0 +1,55 @@
+package fr.gouv.etalab.mastodon.helper;
+
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.support.v4.app.NotificationCompat;
+import android.widget.RemoteViews;
+
+import fr.gouv.etalab.mastodon.R;
+import fr.gouv.etalab.mastodon.activities.NotificationReturnSlot;
+
+public class NotificationPanel {
+
+ private Context parent;
+ private NotificationManager nManager;
+ private NotificationCompat.Builder nBuilder;
+ private RemoteViews remoteView;
+
+ public NotificationPanel(Context parent) {
+ // TODO Auto-generated constructor stub
+ this.parent = parent;
+ nBuilder = new NotificationCompat.Builder(parent)
+ .setContentTitle("Parking Meter")
+ .setSmallIcon(R.drawable.ic_launcher_background)
+ .setOngoing(true);
+
+ remoteView = new RemoteViews(parent.getPackageName(), R.layout.notificationview);
+
+ //set the button listeners
+ setListeners(remoteView);
+ nBuilder.setContent(remoteView);
+
+ nManager = (NotificationManager) parent.getSystemService(Context.NOTIFICATION_SERVICE);
+ nManager.notify(2, nBuilder.build());
+ }
+
+ public void setListeners(RemoteViews view){
+ //listener 1
+ Intent volume = new Intent(parent,NotificationReturnSlot.class);
+ volume.putExtra("DO", "volume");
+ PendingIntent btn1 = PendingIntent.getActivity(parent, 0, volume, 0);
+ view.setOnClickPendingIntent(R.id.btn1, btn1);
+
+ //listener 2
+ Intent stop = new Intent(parent, NotificationReturnSlot.class);
+ stop.putExtra("DO", "stop");
+ PendingIntent btn2 = PendingIntent.getActivity(parent, 1, stop, 0);
+ view.setOnClickPendingIntent(R.id.btn2, btn2);
+ }
+
+ public void notificationCancel() {
+ nManager.cancel(2);
+ }
+} \ No newline at end of file