Merge pull request #231 from freeboub/bugfix/various_crash_fixes
Bugfix/various crash fixes
This commit is contained in:
commit
dc1d9b4823
@ -243,17 +243,22 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL
|
|||||||
Integer videoQuality = sharedPref.getInt(getString(R.string.pref_quality_key), 0);
|
Integer videoQuality = sharedPref.getInt(getString(R.string.pref_quality_key), 0);
|
||||||
|
|
||||||
//get video qualities
|
//get video qualities
|
||||||
String urlToPlay = video.getFiles().get(0).getFileUrl();
|
/// #
|
||||||
for (File file : video.getFiles()) {
|
if (video.getFiles().size() > 0) {
|
||||||
// Set quality if it matches
|
String urlToPlay = video.getFiles().get( 0 ).getFileUrl();
|
||||||
if (file.getResolution().getId().equals(videoQuality)) {
|
for ( File file : video.getFiles() ) {
|
||||||
urlToPlay = file.getFileUrl();
|
// Set quality if it matches
|
||||||
|
if ( file.getResolution().getId().equals( videoQuality ) ) {
|
||||||
|
urlToPlay = file.getFileUrl();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
mService.setCurrentStreamUrl( urlToPlay );
|
||||||
|
torrentStatus.setVisibility(View.GONE);
|
||||||
|
startPlayer();
|
||||||
|
} else {
|
||||||
|
stopVideo();
|
||||||
|
Toast.makeText(context, R.string.api_error, Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
mService.setCurrentStreamUrl(urlToPlay);
|
|
||||||
|
|
||||||
torrentStatus.setVisibility(View.GONE);
|
|
||||||
startPlayer();
|
|
||||||
}
|
}
|
||||||
Log.v(TAG, "end of load Video");
|
Log.v(TAG, "end of load Video");
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ import android.os.Build;
|
|||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.webkit.MimeTypeMap;
|
import android.webkit.MimeTypeMap;
|
||||||
import android.webkit.URLUtil;
|
import android.webkit.URLUtil;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
|
||||||
import com.github.se_bastiaan.torrentstream.TorrentOptions;
|
import com.github.se_bastiaan.torrentstream.TorrentOptions;
|
||||||
@ -40,6 +41,7 @@ import androidx.core.app.ActivityCompat;
|
|||||||
|
|
||||||
public class Intents {
|
public class Intents {
|
||||||
|
|
||||||
|
private static final String TAG = "Intents";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://troll.tv/videos/watch/6edbd9d1-e3c5-4a6c-8491-646e2020469c
|
* https://troll.tv/videos/watch/6edbd9d1-e3c5-4a6c-8491-646e2020469c
|
||||||
@ -68,20 +70,25 @@ public class Intents {
|
|||||||
// TODO, offer which version to download
|
// TODO, offer which version to download
|
||||||
public static void Download(Context context, Video video) {
|
public static void Download(Context context, Video video) {
|
||||||
|
|
||||||
String url = video.getFiles().get(0).getFileDownloadUrl();
|
if (video.getFiles().size() > 0)
|
||||||
// make sure it is a valid filename
|
{
|
||||||
String destFilename = video.getName().replaceAll("[^a-zA-Z0-9]", "_") + "." + MimeTypeMap.getFileExtensionFromUrl(URLUtil.guessFileName(url,null,null));
|
String url = video.getFiles().get( 0 ).getFileDownloadUrl();
|
||||||
|
// make sure it is a valid filename
|
||||||
|
String destFilename = video.getName().replaceAll( "[^a-zA-Z0-9]", "_" ) + "." + MimeTypeMap.getFileExtensionFromUrl( URLUtil.guessFileName( url, null, null ) );
|
||||||
|
|
||||||
//Toast.makeText(context, destFilename, Toast.LENGTH_LONG).show();
|
//Toast.makeText(context, destFilename, Toast.LENGTH_LONG).show();
|
||||||
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
|
DownloadManager.Request request = new DownloadManager.Request( Uri.parse( url ) );
|
||||||
request.setDescription(video.getDescription());
|
request.setDescription( video.getDescription() );
|
||||||
request.setTitle(video.getName());
|
request.setTitle( video.getName() );
|
||||||
request.allowScanningByMediaScanner();
|
request.allowScanningByMediaScanner();
|
||||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
request.setNotificationVisibility( DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED );
|
||||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, destFilename);
|
request.setDestinationInExternalPublicDir( Environment.DIRECTORY_DOWNLOADS, destFilename );
|
||||||
|
|
||||||
// get download service and enqueue file
|
// get download service and enqueue file
|
||||||
DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
|
DownloadManager manager = (DownloadManager) context.getSystemService( Context.DOWNLOAD_SERVICE );
|
||||||
manager.enqueue(request);
|
manager.enqueue( request );
|
||||||
|
} else {
|
||||||
|
Toast.makeText( context, R.string.api_error, Toast.LENGTH_LONG ).show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,8 +113,7 @@ public class VideoPlayerService extends Service {
|
|||||||
if (playbackState
|
if (playbackState
|
||||||
== ACTION_PLAY) { // this means that play is available, hence the audio is paused or stopped
|
== ACTION_PLAY) { // this means that play is available, hence the audio is paused or stopped
|
||||||
Log.v(TAG, "ACTION_PAUSE: " + playbackState);
|
Log.v(TAG, "ACTION_PAUSE: " + playbackState);
|
||||||
unregisterReceiver(myNoisyAudioStreamReceiver);
|
safeUnregisterReceiver();
|
||||||
myNoisyAudioStreamReceiver = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -137,14 +136,9 @@ public class VideoPlayerService extends Service {
|
|||||||
if (playerNotificationManager != null) {
|
if (playerNotificationManager != null) {
|
||||||
playerNotificationManager.setPlayer(null);
|
playerNotificationManager.setPlayer(null);
|
||||||
}
|
}
|
||||||
//Was seeing an error when exiting the program about about not unregistering the receiver.
|
//Was seeing an error when exiting the program about not unregistering the receiver.
|
||||||
try {
|
safeUnregisterReceiver();
|
||||||
if (null != myNoisyAudioStreamReceiver) {
|
|
||||||
this.unregisterReceiver(myNoisyAudioStreamReceiver);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e("VideoPlayerService", "attempted to unregister a nonregistered service");
|
|
||||||
}
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
player.release();
|
player.release();
|
||||||
player = null;
|
player = null;
|
||||||
@ -152,6 +146,15 @@ public class VideoPlayerService extends Service {
|
|||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void safeUnregisterReceiver()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
unregisterReceiver(myNoisyAudioStreamReceiver);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e("VideoPlayerService", "attempted to unregister a nonregistered service");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
|
Loading…
Reference in New Issue
Block a user