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.ProgressiveMediaSource;
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.DefaultTrackSelector;
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.upstream.DataSource;
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.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);
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);
playerView.setPlayer(player);
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);
}
@ -773,34 +782,35 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
Format.NO_VALUE,
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 {
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);
// subtitleSource = new SingleSampleMediaSource(uri, cacheDataSourceFactory, subtitleFormat, C.TIME_UNSET);
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)));
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();
});
@ -1035,8 +1045,12 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
private void initResolution() {
PlayerControlView controlView = playerView.findViewById(R.id.exo_controller);
resolution = controlView.findViewById(R.id.resolution);
resolution.setText(String.format("%s", Helper.defaultFile(PeertubeActivity.this, peertube.getFiles()).getResolutions().getLabel()));
resolution.setOnClickListener(v -> displayResolution());
if( peertube.getFiles() != null && peertube.getFiles().size() > 0) {
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() {

View File

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

View File

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

View File

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

View File

@ -157,10 +157,8 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
if (timelineType == MY_VIDEOS) {
popup.getMenu().findItem(R.id.action_report).setVisible(false);
}else {
if( timelineType == VIDEOS_IN_PLAYLIST) {
popup.getMenu().findItem(R.id.action_edit).setVisible(false);
}else {
popup.getMenu().findItem(R.id.action_edit).setVisible(false);
popup.getMenu().findItem(R.id.action_edit).setVisible(false);
if( timelineType != VIDEOS_IN_PLAYLIST) {
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:
new Thread(() -> {
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());
Runnable myRunnable = () -> {
videos.remove(video);
@ -217,28 +215,17 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
});
popup.show();
});
if (!ownVideos) {
holder.bottom_container.setOnClickListener(v -> {
Intent intent = new Intent(context, PeertubeActivity.class);
Bundle b = new Bundle();
b.putString("video_id", video.getId());
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.bottom_container.setOnClickListener(v -> {
Intent intent = new Intent(context, PeertubeActivity.class);
Bundle b = new Bundle();
b.putString("video_id", video.getUuid());
intent.putExtras(b);
context.startActivity(intent);
});
holder.peertube_video_image.setOnClickListener(v -> {
Intent intent = new Intent(context, PeertubeActivity.class);
Bundle b = new Bundle();
b.putString("video_id", video.getId());
b.putString("video_id", video.getUuid());
intent.putExtras(b);
context.startActivity(intent);
});

View File

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

View File

@ -585,6 +585,9 @@ public class Helper {
* @return File
*/
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);
int video_quality = sharedpreferences.getInt(Helper.SET_QUALITY_MODE, Helper.QUALITY_HIGH);
if (video_quality == QUALITY_HIGH) {

View File

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