mirror of
https://framagit.org/tom79/fedilab-tube
synced 2025-02-16 12:00:42 +01:00
Fix remote videos not playing
This commit is contained in:
parent
e9608f63db
commit
7ceb04d548
@ -2,9 +2,11 @@ Added:
|
|||||||
- playback speed
|
- playback speed
|
||||||
- video attributes (clickable tags)
|
- video attributes (clickable tags)
|
||||||
- update channel photo
|
- update channel photo
|
||||||
|
- higher definition for video preview
|
||||||
|
|
||||||
Changed:
|
Changed:
|
||||||
- Improve player
|
- Improve player
|
||||||
|
- Auto-play next video accessible in player
|
||||||
|
|
||||||
Fixed:
|
Fixed:
|
||||||
- video upload error
|
- video upload error
|
||||||
|
@ -192,6 +192,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||||||
private int initialOrientation;
|
private int initialOrientation;
|
||||||
private String currentResolution;
|
private String currentResolution;
|
||||||
private String currentCaption;
|
private String currentCaption;
|
||||||
|
private boolean isRemote;
|
||||||
|
|
||||||
public static void hideKeyboard(Activity activity) {
|
public static void hideKeyboard(Activity activity) {
|
||||||
if (activity != null && activity.getWindow() != null) {
|
if (activity != null && activity.getWindow() != null) {
|
||||||
@ -254,7 +255,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||||||
Account account = new AccountDAO(PeertubeActivity.this, db).getAccountByToken(token);
|
Account account = new AccountDAO(PeertubeActivity.this, db).getAccountByToken(token);
|
||||||
Helper.loadGiF(PeertubeActivity.this, account.getAvatar() != null ? account.getAvatar().getPath() : null, binding.myPp);
|
Helper.loadGiF(PeertubeActivity.this, account.getAvatar() != null ? account.getAvatar().getPath() : null, binding.myPp);
|
||||||
}
|
}
|
||||||
|
isRemote = false;
|
||||||
TorrentOptions torrentOptions = new TorrentOptions.Builder()
|
TorrentOptions torrentOptions = new TorrentOptions.Builder()
|
||||||
.saveLocation(getCacheDir())
|
.saveLocation(getCacheDir())
|
||||||
.autoDownload(true)
|
.autoDownload(true)
|
||||||
@ -507,6 +508,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||||||
super.onNewIntent(intent);
|
super.onNewIntent(intent);
|
||||||
Bundle b = intent.getExtras();
|
Bundle b = intent.getExtras();
|
||||||
if (b != null) {
|
if (b != null) {
|
||||||
|
isRemote = false;
|
||||||
peertubeInstance = b.getString("peertube_instance", Helper.getLiveInstance(PeertubeActivity.this));
|
peertubeInstance = b.getString("peertube_instance", Helper.getLiveInstance(PeertubeActivity.this));
|
||||||
videoUuid = b.getString("video_uuid", null);
|
videoUuid = b.getString("video_uuid", null);
|
||||||
setRequestedOrientation(initialOrientation);
|
setRequestedOrientation(initialOrientation);
|
||||||
@ -595,7 +597,9 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||||||
binding.peertubePlaylist.setVisibility(View.VISIBLE);
|
binding.peertubePlaylist.setVisibility(View.VISIBLE);
|
||||||
binding.peertubeBookmark.setVisibility(View.GONE);
|
binding.peertubeBookmark.setVisibility(View.GONE);
|
||||||
TimelineVM feedsViewModel = new ViewModelProvider(PeertubeActivity.this).get(TimelineVM.class);
|
TimelineVM feedsViewModel = new ViewModelProvider(PeertubeActivity.this).get(TimelineVM.class);
|
||||||
feedsViewModel.getVideo(sepiaSearch ? peertubeInstance : null, videoUuid, isMyVideo).observe(PeertubeActivity.this, this::manageVIewVideo);
|
if (!isRemote) {
|
||||||
|
feedsViewModel.getVideo(sepiaSearch ? peertubeInstance : null, videoUuid, isMyVideo).observe(PeertubeActivity.this, this::manageVIewVideo);
|
||||||
|
}
|
||||||
CaptionsVM captionsViewModel = new ViewModelProvider(PeertubeActivity.this).get(CaptionsVM.class);
|
CaptionsVM captionsViewModel = new ViewModelProvider(PeertubeActivity.this).get(CaptionsVM.class);
|
||||||
captionsViewModel.getCaptions(sepiaSearch ? peertubeInstance : null, videoUuid).observe(PeertubeActivity.this, this::manageCaptions);
|
captionsViewModel.getCaptions(sepiaSearch ? peertubeInstance : null, videoUuid).observe(PeertubeActivity.this, this::manageCaptions);
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
@ -723,6 +727,50 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
public void manageVIewVideo(APIResponse apiResponse) {
|
public void manageVIewVideo(APIResponse apiResponse) {
|
||||||
|
if (!isRemote && apiResponse != null && apiResponse.getPeertubes().get(0).getErrorCode() == 1 && apiResponse.getPeertubes().get(0).getOriginUrl() != null) {
|
||||||
|
String url = apiResponse.getPeertubes().get(0).getOriginUrl();
|
||||||
|
Pattern link = Pattern.compile("(https?://[\\da-z.-]+\\.[a-z.]{2,10})/videos/watch/(\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12})(\\?start=(\\d+[hH])?(\\d+[mM])?(\\d+[sS])?)?$");
|
||||||
|
Matcher matcherLink = link.matcher(url);
|
||||||
|
if (matcherLink.find()) {
|
||||||
|
String instance = matcherLink.group(1);
|
||||||
|
String uuid = matcherLink.group(2);
|
||||||
|
String hour = matcherLink.group(4);
|
||||||
|
String min = matcherLink.group(5);
|
||||||
|
String sec = matcherLink.group(6);
|
||||||
|
int hourInt, minInt, secInt;
|
||||||
|
int totalSeconds = 0;
|
||||||
|
if (hour != null) {
|
||||||
|
hourInt = Integer.parseInt(hour.replace("h", ""));
|
||||||
|
totalSeconds += 3600 * hourInt;
|
||||||
|
}
|
||||||
|
if (min != null) {
|
||||||
|
minInt = Integer.parseInt(min.replace("m", ""));
|
||||||
|
totalSeconds += 60 * minInt;
|
||||||
|
}
|
||||||
|
if (sec != null) {
|
||||||
|
secInt = Integer.parseInt(sec.replace("s", ""));
|
||||||
|
totalSeconds += secInt;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (instance != null && uuid != null) {
|
||||||
|
peertubeInstance = instance.replace("https://", "").replace("http://", "");
|
||||||
|
sepiaSearch = true; // Sepia search flag is used because, at this time we don't know if the video is federated.
|
||||||
|
videoUuid = uuid;
|
||||||
|
peertube = new VideoData.Video();
|
||||||
|
peertube.setUuid(uuid);
|
||||||
|
peertube.setEmbedUrl(url);
|
||||||
|
isRemote = true;
|
||||||
|
if (totalSeconds > 0) {
|
||||||
|
VideoData.UserHistory userHistory = new VideoData.UserHistory();
|
||||||
|
userHistory.setCurrentTime(totalSeconds * 1000);
|
||||||
|
peertube.setUserHistory(userHistory);
|
||||||
|
}
|
||||||
|
TimelineVM viewModelTimeline = new ViewModelProvider(PeertubeActivity.this).get(TimelineVM.class);
|
||||||
|
viewModelTimeline.getVideo(peertubeInstance, peertube.getUuid(), false).observe(PeertubeActivity.this, this::manageVIewVideo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (apiResponse == null || (apiResponse.getError() != null) || apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0) {
|
if (apiResponse == null || (apiResponse.getError() != null) || apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0) {
|
||||||
Toasty.error(PeertubeActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
Toasty.error(PeertubeActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
||||||
binding.loader.setVisibility(View.GONE);
|
binding.loader.setVisibility(View.GONE);
|
||||||
@ -793,7 +841,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||||||
SpannableString spannableString = new SpannableString(sb.toString());
|
SpannableString spannableString = new SpannableString(sb.toString());
|
||||||
for (String tag : tags) {
|
for (String tag : tags) {
|
||||||
String target = "#" + tag;
|
String target = "#" + tag;
|
||||||
if (spannableString != null && spannableString.toString().contains(target)) {
|
if (spannableString.toString().contains(target)) {
|
||||||
for (int startPosition = -1; (startPosition = spannableString.toString().indexOf(target, startPosition + 1)) != -1; startPosition++) {
|
for (int startPosition = -1; (startPosition = spannableString.toString().indexOf(target, startPosition + 1)) != -1; startPosition++) {
|
||||||
final int endPosition = startPosition + target.length();
|
final int endPosition = startPosition + target.length();
|
||||||
if (endPosition <= spannableString.toString().length() && endPosition >= startPosition) {
|
if (endPosition <= spannableString.toString().length() && endPosition >= startPosition) {
|
||||||
|
@ -27,6 +27,8 @@ import android.webkit.MimeTypeMap;
|
|||||||
import androidx.documentfile.provider.DocumentFile;
|
import androidx.documentfile.provider.DocumentFile;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -1673,19 +1675,37 @@ public class RetrofitPeertubeAPI {
|
|||||||
APIResponse apiResponse = new APIResponse();
|
APIResponse apiResponse = new APIResponse();
|
||||||
try {
|
try {
|
||||||
Response<VideoData.Video> response = video.execute();
|
Response<VideoData.Video> response = video.execute();
|
||||||
|
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
List<VideoData.Video> videos = new ArrayList<>();
|
List<VideoData.Video> videos = new ArrayList<>();
|
||||||
videos.add(response.body());
|
videos.add(response.body());
|
||||||
apiResponse.setPeertubes(videos);
|
apiResponse.setPeertubes(videos);
|
||||||
} else {
|
} else {
|
||||||
Error error = new Error();
|
|
||||||
error.setStatusCode(response.code());
|
|
||||||
if (response.errorBody() != null) {
|
if (response.errorBody() != null) {
|
||||||
error.setError(response.errorBody().string());
|
String error = response.errorBody().string();
|
||||||
|
if (error.contains("originUrl")) {
|
||||||
|
try {
|
||||||
|
JSONObject jsonObject = new JSONObject(error);
|
||||||
|
List<VideoData.Video> videos = new ArrayList<>();
|
||||||
|
VideoData.Video videoRedirect = new VideoData.Video();
|
||||||
|
videoRedirect.setErrorCode(jsonObject.getInt("errorCode"));
|
||||||
|
videoRedirect.setOriginUrl(jsonObject.getString("originUrl"));
|
||||||
|
videos.add(videoRedirect);
|
||||||
|
apiResponse.setPeertubes(videos);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
error.setError(_context.getString(R.string.toast_error));
|
Error error = new Error();
|
||||||
|
error.setStatusCode(response.code());
|
||||||
|
if (response.errorBody() != null) {
|
||||||
|
error.setError(response.errorBody().string());
|
||||||
|
} else {
|
||||||
|
error.setError(_context.getString(R.string.toast_error));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Error error = new Error();
|
Error error = new Error();
|
||||||
|
@ -43,6 +43,7 @@ public class VideoData {
|
|||||||
@SerializedName("data")
|
@SerializedName("data")
|
||||||
public List<Video> data;
|
public List<Video> data;
|
||||||
|
|
||||||
|
|
||||||
public static class Video implements Parcelable {
|
public static class Video implements Parcelable {
|
||||||
public static final Creator<Video> CREATOR = new Creator<Video>() {
|
public static final Creator<Video> CREATOR = new Creator<Video>() {
|
||||||
@Override
|
@Override
|
||||||
@ -130,6 +131,8 @@ public class VideoData {
|
|||||||
@SerializedName("waitTranscoding")
|
@SerializedName("waitTranscoding")
|
||||||
private boolean waitTranscoding;
|
private boolean waitTranscoding;
|
||||||
private String myRating;
|
private String myRating;
|
||||||
|
private String originUrl;
|
||||||
|
private int errorCode;
|
||||||
//Dedicated to overview videos to reuse the logic of videos
|
//Dedicated to overview videos to reuse the logic of videos
|
||||||
private boolean hasTitle = false;
|
private boolean hasTitle = false;
|
||||||
private String title;
|
private String title;
|
||||||
@ -541,6 +544,22 @@ public class VideoData {
|
|||||||
this.waitTranscoding = waitTranscoding;
|
this.waitTranscoding = waitTranscoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getOriginUrl() {
|
||||||
|
return originUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOriginUrl(String originUrl) {
|
||||||
|
this.originUrl = originUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getErrorCode() {
|
||||||
|
return errorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setErrorCode(int errorCode) {
|
||||||
|
this.errorCode = errorCode;
|
||||||
|
}
|
||||||
|
|
||||||
public String getMyRating() {
|
public String getMyRating() {
|
||||||
return myRating;
|
return myRating;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user