Merge pull request #89 from lishoujun/develop

Stop torrentStream  when activity onDestroy.
This commit is contained in:
Stefan Schüller 2019-01-02 19:27:07 +01:00 committed by GitHub
commit eca8a54e7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 10 deletions

View File

@ -9,6 +9,11 @@ android {
versionCode 1020 versionCode 1020
versionName "1.0.20" versionName "1.0.20"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ext {
libVersions = [
exoplayer: '2.9.3'
]
}
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
@ -41,13 +46,13 @@ android {
// implementation "com.github.TorrentStream:TorrentStreamServer-Android:1.0.1" // implementation "com.github.TorrentStream:TorrentStreamServer-Android:1.0.1"
// implementation 'org.webrtc:google-webrtc:1.0.+' // implementation 'org.webrtc:google-webrtc:1.0.+'
// video player // video player repo:jcenter()
implementation 'com.google.android.exoplayer:exoplayer-core:2.9.2' implementation "com.google.android.exoplayer:exoplayer-core:$libVersions.exoplayer"
implementation 'com.google.android.exoplayer:exoplayer-dash:2.9.2' implementation "com.google.android.exoplayer:exoplayer-dash:$libVersions.exoplayer"
implementation 'com.google.android.exoplayer:exoplayer-ui:2.9.2' implementation "com.google.android.exoplayer:exoplayer-ui:$libVersions.exoplayer"
implementation 'com.google.android.exoplayer:exoplayer-hls:2.9.2' implementation "com.google.android.exoplayer:exoplayer-hls:$libVersions.exoplayer"
implementation 'com.google.android.exoplayer:exoplayer-smoothstreaming:2.9.2' implementation "com.google.android.exoplayer:exoplayer-smoothstreaming:$libVersions.exoplayer"
implementation 'com.google.android.exoplayer:extension-mediasession:2.9.2' implementation "com.google.android.exoplayer:extension-mediasession:$libVersions.exoplayer"
// testing // testing
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'

View File

@ -66,6 +66,7 @@ import net.schueller.peertube.fragment.VideoOptionsFragment;
import net.schueller.peertube.helper.APIUrlHelper; import net.schueller.peertube.helper.APIUrlHelper;
import net.schueller.peertube.helper.MetaDataHelper; import net.schueller.peertube.helper.MetaDataHelper;
import net.schueller.peertube.intents.Intents; import net.schueller.peertube.intents.Intents;
import net.schueller.peertube.model.Account;
import net.schueller.peertube.model.Avatar; import net.schueller.peertube.model.Avatar;
import net.schueller.peertube.model.Video; import net.schueller.peertube.model.Video;
import net.schueller.peertube.network.GetVideoDataService; import net.schueller.peertube.network.GetVideoDataService;
@ -89,7 +90,7 @@ public class VideoPlayActivity extends AppCompatActivity implements VideoRendere
private Context context = this; private Context context = this;
private TextView fullscreenButton; private TextView fullscreenButton;
private Boolean isFullscreen = false; private Boolean isFullscreen = false;
private TorrentStream torrentStream;
boolean mBound = false; boolean mBound = false;
VideoPlayerService mService; VideoPlayerService mService;
@ -296,7 +297,16 @@ public class VideoPlayActivity extends AppCompatActivity implements VideoRendere
String baseUrl = APIUrlHelper.getUrl(context); String baseUrl = APIUrlHelper.getUrl(context);
Avatar avatar = video.getAccount().getAvatar(); if(video == null){
Toast.makeText(VideoPlayActivity.this, "Something went wrong...Please try later!", Toast.LENGTH_SHORT).show();
return;
}
Account account = video.getAccount();
if(account == null){
Toast.makeText(VideoPlayActivity.this, "Something went wrong...Please try later!", Toast.LENGTH_SHORT).show();
return;
}
Avatar avatar = account.getAvatar();
if (avatar != null) { if (avatar != null) {
String avatarPath = avatar.getPath(); String avatarPath = avatar.getPath();
Picasso.with(context) Picasso.with(context)
@ -349,6 +359,7 @@ public class VideoPlayActivity extends AppCompatActivity implements VideoRendere
videoOptionsFragment.show(getSupportFragmentManager(), videoOptionsFragment.show(getSupportFragmentManager(),
"video_options_fragment"); "video_options_fragment");
}); });
Log.v(TAG, "url : " + video.getFiles().get(0).getFileUrl());
mService.setCurrentStreamUrl(video.getFiles().get(0).getFileUrl()); mService.setCurrentStreamUrl(video.getFiles().get(0).getFileUrl());
@ -357,11 +368,13 @@ public class VideoPlayActivity extends AppCompatActivity implements VideoRendere
if (sharedPref.getBoolean("pref_torrent_player", false)) { if (sharedPref.getBoolean("pref_torrent_player", false)) {
String stream = video.getFiles().get(0).getTorrentUrl(); String stream = video.getFiles().get(0).getTorrentUrl();
TorrentStream torrentStream = setupTorrentStream(); Log.v(TAG, "getTorrentUrl : " + video.getFiles().get(0).getTorrentUrl());
torrentStream = setupTorrentStream();
torrentStream.startStream(stream); torrentStream.startStream(stream);
} else { } else {
startPlayer(); startPlayer();
} }
Log.v(TAG,"end of load Video");
} }
@ -414,6 +427,10 @@ public class VideoPlayActivity extends AppCompatActivity implements VideoRendere
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
simpleExoPlayerView.setPlayer(null); simpleExoPlayerView.setPlayer(null);
if (torrentStream != null){
torrentStream.stopStream();
}
Log.v(TAG, "onDestroy...");
} }
@Override @Override