1
0
mirror of https://framagit.org/tom79/fedilab-tube synced 2025-02-17 20:40:43 +01:00

some fixes

This commit is contained in:
Thomas 2020-10-06 17:11:25 +02:00
parent 752e3d50c1
commit 6a762a8fd6
8 changed files with 105 additions and 94 deletions

View File

@ -72,6 +72,7 @@ import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.MergingMediaSource; import com.google.android.exoplayer2.source.MergingMediaSource;
import com.google.android.exoplayer2.source.ProgressiveMediaSource; import com.google.android.exoplayer2.source.ProgressiveMediaSource;
import com.google.android.exoplayer2.source.SingleSampleMediaSource; import com.google.android.exoplayer2.source.SingleSampleMediaSource;
import com.google.android.exoplayer2.source.hls.HlsMediaSource;
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection; import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelector; import com.google.android.exoplayer2.trackselection.TrackSelector;
@ -80,6 +81,7 @@ import com.google.android.exoplayer2.ui.PlayerControlView;
import com.google.android.exoplayer2.ui.PlayerView; import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
@ -665,21 +667,28 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB); int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB);
ProgressiveMediaSource videoSource; ProgressiveMediaSource videoSource;
if (video_cache == 0) {
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this,
Util.getUserAgent(PeertubeActivity.this, null), null);
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this)));
} else {
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this);
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this)));
}
player = ExoPlayerFactory.newSimpleInstance(PeertubeActivity.this); player = ExoPlayerFactory.newSimpleInstance(PeertubeActivity.this);
playerView.setPlayer(player); playerView.setPlayer(player);
loader.setVisibility(View.GONE); loader.setVisibility(View.GONE);
player.prepare(videoSource);
if( apiResponse.getPeertubes().get(0).getFiles() != null && apiResponse.getPeertubes().get(0).getFiles().size() > 0) {
if (video_cache == 0) {
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this,
Util.getUserAgent(PeertubeActivity.this, null), null);
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this)));
} else {
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this);
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this)));
}
player.prepare(videoSource);
}else{
HlsMediaSource hlsMediaSource = new HlsMediaSource.Factory(new DefaultHttpDataSourceFactory(System.getProperty("http.agent")))
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getStreamingPlaylists().get(0).getPlaylistUrl()));
player.prepare(hlsMediaSource);
}
player.setPlayWhenReady(true); player.setPlayWhenReady(true);
} }
@ -773,34 +782,35 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
Format.NO_VALUE, Format.NO_VALUE,
itemsKeyLanguage[which]); itemsKeyLanguage[which]);
if (video_cache == 0) {
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this,
Util.getUserAgent(PeertubeActivity.this, null), null);
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this)));
if (uri != null)
subtitleSource = new SingleSampleMediaSource.Factory(dataSourceFactory).createMediaSource(uri, subtitleFormat, C.TIME_UNSET);
// subtitleSource = new SingleSampleMediaSource(uri, dataSourceFactory, subtitleFormat, C.TIME_UNSET);
} else { if( apiResponse.getPeertubes().get(0).getFiles() != null && apiResponse.getPeertubes().get(0).getFiles().size() > 0) {
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this); if (video_cache == 0) {
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory) DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this,
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this))); Util.getUserAgent(PeertubeActivity.this, null), null);
if (uri != null) videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
subtitleSource = new SingleSampleMediaSource.Factory(cacheDataSourceFactory).createMediaSource(uri, subtitleFormat, C.TIME_UNSET); .createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this)));
// subtitleSource = new SingleSampleMediaSource(uri, cacheDataSourceFactory, subtitleFormat, C.TIME_UNSET); if (uri != null)
subtitleSource = new SingleSampleMediaSource.Factory(dataSourceFactory).createMediaSource(uri, subtitleFormat, C.TIME_UNSET);
} else {
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this);
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this)));
if (uri != null)
subtitleSource = new SingleSampleMediaSource.Factory(cacheDataSourceFactory).createMediaSource(uri, subtitleFormat, C.TIME_UNSET);
}
playerView.setPlayer(player);
if (which > 0 && subtitleSource != null) {
MergingMediaSource mergedSource =
new MergingMediaSource(videoSource, subtitleSource);
player.prepare(mergedSource);
} else {
player.prepare(videoSource);
}
player.seekTo(0, position);
player.setPlayWhenReady(true);
} }
playerView.setPlayer(player);
if (which > 0 && subtitleSource != null) {
MergingMediaSource mergedSource =
new MergingMediaSource(videoSource, subtitleSource);
player.prepare(mergedSource);
} else {
player.prepare(videoSource);
}
player.seekTo(0, position);
player.setPlayWhenReady(true);
dialog.dismiss(); dialog.dismiss();
}); });
@ -1035,8 +1045,12 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
private void initResolution() { private void initResolution() {
PlayerControlView controlView = playerView.findViewById(R.id.exo_controller); PlayerControlView controlView = playerView.findViewById(R.id.exo_controller);
resolution = controlView.findViewById(R.id.resolution); resolution = controlView.findViewById(R.id.resolution);
resolution.setText(String.format("%s", Helper.defaultFile(PeertubeActivity.this, peertube.getFiles()).getResolutions().getLabel())); if( peertube.getFiles() != null && peertube.getFiles().size() > 0) {
resolution.setOnClickListener(v -> displayResolution()); resolution.setText(String.format("%s", Helper.defaultFile(PeertubeActivity.this, peertube.getFiles()).getResolutions().getLabel()));
resolution.setOnClickListener(v -> displayResolution());
}else{
resolution.setVisibility(View.GONE);
}
} }
private void changeColor() { private void changeColor() {

View File

@ -162,6 +162,7 @@ public class PlaylistsActivity extends AppCompatActivity {
List<VideoPlaylistData.VideoPlaylist> videoPlaylists = apiResponse.getVideoPlaylist(); List<VideoPlaylistData.VideoPlaylist> videoPlaylists = apiResponse.getVideoPlaylist();
List<Video> videos = new ArrayList<>(); List<Video> videos = new ArrayList<>();
for (VideoPlaylistData.VideoPlaylist v : videoPlaylists) { for (VideoPlaylistData.VideoPlaylist v : videoPlaylists) {
v.getVideo().setIdInPlaylist(v.getId());
videos.add(v.getVideo()); videos.add(v.getVideo());
} }
max_id = apiResponse.getMax_id(); max_id = apiResponse.getMax_id();

View File

@ -21,7 +21,6 @@ import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.util.Log;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -1113,7 +1112,6 @@ public class RetrofitPeertubeAPI {
APIResponse apiResponse = new APIResponse(); APIResponse apiResponse = new APIResponse();
try { try {
Log.v(Helper.TAG,"type: " + type);
if (type == PlaylistsVM.action.GET_PLAYLIST_INFO) { if (type == PlaylistsVM.action.GET_PLAYLIST_INFO) {
Call<PlaylistData.Playlist> playlistCall = peertubeService.getPlaylist(playlistId); Call<PlaylistData.Playlist> playlistCall = peertubeService.getPlaylist(playlistId);
Response<PlaylistData.Playlist> response = playlistCall.execute(); Response<PlaylistData.Playlist> response = playlistCall.execute();
@ -1158,15 +1156,11 @@ public class RetrofitPeertubeAPI {
setError(apiResponse, response.code(), response.errorBody()); setError(apiResponse, response.code(), response.errorBody());
} }
} else if (type == PlaylistsVM.action.DELETE_VIDEOS) { } else if (type == PlaylistsVM.action.DELETE_VIDEOS) {
Log.v(Helper.TAG,"playlistId: " + playlistId);
Log.v(Helper.TAG,"videoId: " + videoId);
Call<String> stringCall = peertubeService.deleteVideoInPlaylist(getToken(), playlistId, videoId); Call<String> stringCall = peertubeService.deleteVideoInPlaylist(getToken(), playlistId, videoId);
Response<String> response = stringCall.execute(); Response<String> response = stringCall.execute();
if (response.isSuccessful()) { if (response.isSuccessful()) {
Log.v(Helper.TAG,"ok: " + response.body());
apiResponse.setActionReturn(response.body()); apiResponse.setActionReturn(response.body());
} else { } else {
Log.v(Helper.TAG,"err: " + response.errorBody().string());
setError(apiResponse, response.code(), response.errorBody()); setError(apiResponse, response.code(), response.errorBody());
} }
} }

View File

@ -129,6 +129,7 @@ public class VideoData {
private boolean hasTitle = false; private boolean hasTitle = false;
private String title; private String title;
private titleType titleType; private titleType titleType;
private String idInPlaylist;
public Video() { public Video() {
} }
@ -182,29 +183,34 @@ public class VideoData {
public String getFileUrl(String resolution, Context context) { public String getFileUrl(String resolution, Context context) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean streamService = sharedpreferences.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL) == Helper.VIDEO_MODE_STREAMING; boolean streamService = sharedpreferences.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL) == Helper.VIDEO_MODE_STREAMING;
if (resolution != null) { if(files != null && files.size() > 0) {
for (File file : files) { if (resolution != null) {
if (file.getResolutions().getLabel().compareTo(resolution) == 0) { for (File file : files) {
if (streamService) { if (file.getResolutions().getLabel().compareTo(resolution) == 0) {
return file.getMagnetUri(); if (streamService) {
} else { return file.getMagnetUri();
return file.getFileUrl(); } else {
return file.getFileUrl();
} }
} }
} }
} }
File file = Helper.defaultFile(context, files); File file = Helper.defaultFile(context, files);
if( file != null) { if (file != null) {
if (streamService) { if (streamService) {
return file.getMagnetUri(); return file.getMagnetUri();
} else { } else {
return file.getFileUrl(); return file.getFileUrl();
} }
}else{ } else {
return null; return null;
} }
}else if(streamingPlaylists != null && streamingPlaylists.size() > 0){
return streamingPlaylists.get(0).getPlaylistUrl();
}
return null;
} }
public String getTorrentUrl(String resolution, Context context) { public String getTorrentUrl(String resolution, Context context) {
@ -550,6 +556,14 @@ public class VideoData {
this.titleType = titleType; this.titleType = titleType;
} }
public String getIdInPlaylist() {
return idInPlaylist;
}
public void setIdInPlaylist(String idInPlaylist) {
this.idInPlaylist = idInPlaylist;
}
@Override @Override
public int describeContents() { public int describeContents() {
return 0; return 0;

View File

@ -157,10 +157,8 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
if (timelineType == MY_VIDEOS) { if (timelineType == MY_VIDEOS) {
popup.getMenu().findItem(R.id.action_report).setVisible(false); popup.getMenu().findItem(R.id.action_report).setVisible(false);
}else { }else {
if( timelineType == VIDEOS_IN_PLAYLIST) { popup.getMenu().findItem(R.id.action_edit).setVisible(false);
popup.getMenu().findItem(R.id.action_edit).setVisible(false); if( timelineType != VIDEOS_IN_PLAYLIST) {
}else {
popup.getMenu().findItem(R.id.action_edit).setVisible(false);
popup.getMenu().findItem(R.id.action_remove_playlist).setVisible(false); popup.getMenu().findItem(R.id.action_remove_playlist).setVisible(false);
} }
} }
@ -169,7 +167,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
case R.id.action_remove_playlist: case R.id.action_remove_playlist:
new Thread(() -> { new Thread(() -> {
PlaylistsVM playlistsViewModel = new ViewModelProvider((ViewModelStoreOwner) context).get(PlaylistsVM.class); PlaylistsVM playlistsViewModel = new ViewModelProvider((ViewModelStoreOwner) context).get(PlaylistsVM.class);
playlistsViewModel.manage(PlaylistsVM.action.DELETE_VIDEOS, playlist, video.getId()); playlistsViewModel.manage(PlaylistsVM.action.DELETE_VIDEOS, playlist, video.getIdInPlaylist());
Handler mainHandler = new Handler(Looper.getMainLooper()); Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> { Runnable myRunnable = () -> {
videos.remove(video); videos.remove(video);
@ -217,28 +215,17 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
}); });
popup.show(); popup.show();
}); });
holder.bottom_container.setOnClickListener(v -> {
if (!ownVideos) { Intent intent = new Intent(context, PeertubeActivity.class);
holder.bottom_container.setOnClickListener(v -> { Bundle b = new Bundle();
Intent intent = new Intent(context, PeertubeActivity.class); b.putString("video_id", video.getUuid());
Bundle b = new Bundle(); intent.putExtras(b);
b.putString("video_id", video.getId()); context.startActivity(intent);
intent.putExtras(b); });
context.startActivity(intent);
});
} else {
holder.bottom_container.setOnClickListener(v -> {
Intent intent = new Intent(context, PeertubeEditUploadActivity.class);
Bundle b = new Bundle();
b.putString("video_id", video.getUuid());
intent.putExtras(b);
context.startActivity(intent);
});
}
holder.peertube_video_image.setOnClickListener(v -> { holder.peertube_video_image.setOnClickListener(v -> {
Intent intent = new Intent(context, PeertubeActivity.class); Intent intent = new Intent(context, PeertubeActivity.class);
Bundle b = new Bundle(); Bundle b = new Bundle();
b.putString("video_id", video.getId()); b.putString("video_id", video.getUuid());
intent.putExtras(b); intent.putExtras(b);
context.startActivity(intent); context.startActivity(intent);
}); });

View File

@ -131,7 +131,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
mainLoader.setVisibility(View.VISIBLE); mainLoader.setVisibility(View.VISIBLE);
nextElementLoader.setVisibility(View.GONE); nextElementLoader.setVisibility(View.GONE);
peertubeAdapater = new PeertubeAdapter(this.peertubes, TimelineVM.TimelineType.MY_VIDEOS); peertubeAdapater = new PeertubeAdapter(this.peertubes, type);
lv_status.setAdapter(peertubeAdapater); lv_status.setAdapter(peertubeAdapater);
accountsHorizontalListAdapter = new AccountsHorizontalListAdapter(this.accounts, this); accountsHorizontalListAdapter = new AccountsHorizontalListAdapter(this.accounts, this);
@ -317,7 +317,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
this.peertubes.addAll(apiResponse.getPeertubes()); this.peertubes.addAll(apiResponse.getPeertubes());
//If no item were inserted previously the adapter is created //If no item were inserted previously the adapter is created
if (previousPosition == 0) { if (previousPosition == 0) {
peertubeAdapater = new PeertubeAdapter(this.peertubes, TimelineVM.TimelineType.MY_VIDEOS); peertubeAdapater = new PeertubeAdapter(this.peertubes, type);
lv_status.setAdapter(peertubeAdapater); lv_status.setAdapter(peertubeAdapater);
} else } else
peertubeAdapater.notifyItemRangeInserted(previousPosition, apiResponse.getPeertubes().size()); peertubeAdapater.notifyItemRangeInserted(previousPosition, apiResponse.getPeertubes().size());

View File

@ -585,6 +585,9 @@ public class Helper {
* @return File * @return File
*/ */
public static File defaultFile(Context context, List<File> files) { public static File defaultFile(Context context, List<File> files) {
if( files == null || files.size() == 0) {
return null;
}
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int video_quality = sharedpreferences.getInt(Helper.SET_QUALITY_MODE, Helper.QUALITY_HIGH); int video_quality = sharedpreferences.getInt(Helper.SET_QUALITY_MODE, Helper.QUALITY_HIGH);
if (video_quality == QUALITY_HIGH) { if (video_quality == QUALITY_HIGH) {

View File

@ -20,7 +20,6 @@ import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel; import androidx.lifecycle.AndroidViewModel;
@ -82,8 +81,7 @@ public class PlaylistsVM extends AndroidViewModel {
apiResponse = new APIResponse(); apiResponse = new APIResponse();
apiResponse.setPlaylists(new ArrayList<>()); apiResponse.setPlaylists(new ArrayList<>());
} else { } else {
Log.v(Helper.TAG,"managePlaylists: " + account); apiResponse = new RetrofitPeertubeAPI(_mContext).playlistAction(apiAction, playlist != null ? playlist.getId() : null, videoId, account.getAcct());
apiResponse = new RetrofitPeertubeAPI(_mContext).playlistAction(apiAction, playlist != null ? playlist.getUuid() : null, videoId, account.getAcct());
} }
Handler mainHandler = new Handler(Looper.getMainLooper()); Handler mainHandler = new Handler(Looper.getMainLooper());
if (apiResponse != null) { if (apiResponse != null) {