Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Release v1.0.54

See merge request sschueller/peertube!14
  • Loading branch information
sschueller committed Jan 25, 2021
2 parents a937a51 + 22f3cdc commit 0ff5923
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### Version 1.0.54 Tag: v1.0.54 (2021-01-24)
- Added HLS playback support

### Version 1.0.53 Tag: v1.0.53 (2021-01-24)
- Making X in pip mode stop background audio properly (@dhk2)
- Adding clear search history option to settings menu (@dhk2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,29 @@ private void playVideo(Video video) {

Integer videoQuality = sharedPref.getInt(getString(R.string.pref_quality_key), 999999);

String urlToPlay = null;
boolean isHLS = false;

// try HLS stream first
// get video qualities
// TODO: if auto is set all versions except 0p should be added to a track and have exoplayer auto select optimal bitrate
if (video.getFiles().size() > 0) {
String urlToPlay = video.getFiles().get( 0 ).getFileUrl(); // default, take first found, usually highest res
for ( File file : video.getFiles() ) {
// Set quality if it matches
if ( file.getResolution().getId().equals( videoQuality ) ) {
urlToPlay = file.getFileUrl();
if (video.getStreamingPlaylists().size() > 0) {
urlToPlay = video.getStreamingPlaylists().get( 0 ).getPlaylistUrl();
isHLS = true;
} else {
if (video.getFiles().size() > 0) {
urlToPlay = video.getFiles().get( 0 ).getFileUrl(); // default, take first found, usually highest res
for ( File file : video.getFiles() ) {
// Set quality if it matches
if ( file.getResolution().getId().equals( videoQuality ) ) {
urlToPlay = file.getFileUrl();
}
}
}
mService.setCurrentStreamUrl( urlToPlay );
}

if (!urlToPlay.isEmpty()) {
mService.setCurrentStreamUrl( urlToPlay, isHLS);
torrentStatus.setVisibility(View.GONE);
startPlayer();
} else {
Expand Down Expand Up @@ -357,7 +369,7 @@ private TorrentStream setupTorrentStream() {
public void onStreamReady(Torrent torrent) {
String videopath = Uri.fromFile(torrent.getVideoFile()).toString();
Log.d(TAG, "Ready! torrentStream videopath:" + videopath);
mService.setCurrentStreamUrl(videopath);
mService.setCurrentStreamUrl(videopath, false);
startPlayer();
}

Expand Down
39 changes: 39 additions & 0 deletions app/src/main/java/net/schueller/peertube/model/State.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2020 Stefan Schüller <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.schueller.peertube.model;

public class State {

private Integer id;
private String label;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (C) 2020 Stefan Schüller <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.schueller.peertube.model;

import java.util.ArrayList;

public class StreamingPlaylist {

private Integer id;
private Integer type;
private String playlistUrl;
private String segmentsSha256Url;
private ArrayList<String> redundancies;
private ArrayList<File> files;

public Integer getId() {
return id;
}

public void setId(final Integer id) {
this.id = id;
}

public Integer getType() {
return type;
}

public void setType(final Integer type) {
this.type = type;
}

public String getPlaylistUrl() {
return playlistUrl;
}

public void setPlaylistUrl(final String playlistUrl) {
this.playlistUrl = playlistUrl;
}

public String getSegmentsSha256Url() {
return segmentsSha256Url;
}

public void setSegmentsSha256Url(final String segmentsSha256Url) {
this.segmentsSha256Url = segmentsSha256Url;
}

public ArrayList<String> getRedundancies() {
return redundancies;
}

public void setRedundancies(final ArrayList<String> redundancies) {
this.redundancies = redundancies;
}

public ArrayList<File> getFiles() {
return files;
}

public void setFiles(final ArrayList<File> files) {
this.files = files;
}
}
52 changes: 49 additions & 3 deletions app/src/main/java/net/schueller/peertube/model/Video.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,19 @@ public class Video {

private Channel channel;
private Account account;
private ArrayList tags;
private ArrayList<String> tags;

private Boolean commentsEnabled;
private Boolean downloadEnabled;
private Boolean waitTranscoding;

private State state;
private ArrayList<String> trackerUrls;

private ArrayList<File> files;

private ArrayList<StreamingPlaylist> streamingPlaylists;

public Video() {

}
Expand Down Expand Up @@ -253,11 +261,11 @@ public void setAccount(Account account) {
this.account = account;
}

public ArrayList getTags() {
public ArrayList<String> getTags() {
return tags;
}

public void setTags(ArrayList tags) {
public void setTags(ArrayList<String> tags) {
this.tags = tags;
}

Expand All @@ -277,7 +285,45 @@ public void setFiles(ArrayList<File> files) {
this.files = files;
}

public Boolean getDownloadEnabled() {
return downloadEnabled;
}

public void setDownloadEnabled(final Boolean downloadEnabled) {
this.downloadEnabled = downloadEnabled;
}

public Boolean getWaitTranscoding() {
return waitTranscoding;
}

public void setWaitTranscoding(final Boolean waitTranscoding) {
this.waitTranscoding = waitTranscoding;
}

public State getState() {
return state;
}

public void setState(final State state) {
this.state = state;
}

public ArrayList<String> getTrackerUrls() {
return trackerUrls;
}

public void setTrackerUrls(final ArrayList<String> trackerUrls) {
this.trackerUrls = trackerUrls;
}

public ArrayList<StreamingPlaylist> getStreamingPlaylists() {
return streamingPlaylists;
}

public void setStreamingPlaylists(final ArrayList<StreamingPlaylist> streamingPlaylists) {
this.streamingPlaylists = streamingPlaylists;
}

public static MediaDescriptionCompat getMediaDescription(Context context, Video video) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import com.google.android.exoplayer2.source.ExtractorMediaSource;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
import com.google.android.exoplayer2.source.hls.HlsMediaSource;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.ui.PlayerNotificationManager;
import com.google.android.exoplayer2.upstream.DataSource;
Expand Down Expand Up @@ -93,6 +94,8 @@ public class VideoPlayerService extends Service {

private String currentStreamUrl;

private boolean currentStreamUrlIsHLS;

private PlayerNotificationManager playerNotificationManager;

private IntentFilter becomeNoisyIntentFilter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
Expand Down Expand Up @@ -190,8 +193,9 @@ public void setCurrentVideo(Video video) {
currentVideo = video;
}

public void setCurrentStreamUrl(String streamUrl) {
public void setCurrentStreamUrl(String streamUrl, boolean isHLS) {
Log.v(TAG, "setCurrentStreamUrl..." + streamUrl);
currentStreamUrlIsHLS = isHLS;
currentStreamUrl = streamUrl;
}

Expand Down Expand Up @@ -233,8 +237,14 @@ public void playVideo() {
DataSource.Factory dataSourceFactory = new OkHttpDataSourceFactory(okhttpClientBuilder.build(), Util.getUserAgent(getApplicationContext(), "PeerTube"));

// Create a progressive media source pointing to a stream uri.
MediaSource mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(MediaItem.fromUri(Uri.parse(currentStreamUrl)));
MediaSource mediaSource;
if (currentStreamUrlIsHLS) {
mediaSource = new HlsMediaSource.Factory(dataSourceFactory)
.createMediaSource(MediaItem.fromUri(Uri.parse(currentStreamUrl)));
} else {
mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(MediaItem.fromUri(Uri.parse(currentStreamUrl)));
}

// Set the media source to be played.
player.setMediaSource(mediaSource);
Expand Down
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/1054.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Added HLS playback support

0 comments on commit 0ff5923

Please sign in to comment.