Commit 3b00b901 authored by Geoffrey Métais's avatar Geoffrey Métais

Skip media loading if uri is invalid

parent ad9f5731
......@@ -244,11 +244,15 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
launch(UI, CoroutineStart.UNDISPATCHED) {
if (mw.hasFlag(MediaWrapper.MEDIA_FORCE_AUDIO) && player.getAudioTracksCount() == 0) {
determinePrevAndNextIndices(true)
if (currentIndex != nextIndex) next()
else stop(false)
skipMedia()
} else if (mw.type != MediaWrapper.TYPE_VIDEO || isVideoPlaying || player.hasRenderer
|| mw.hasFlag(MediaWrapper.MEDIA_FORCE_AUDIO)) {
val media = Media(VLCInstance.get(), FileUtils.getUri(mw.uri))
val uri = FileUtils.getUri(mw.uri)
if (uri == null) {
skipMedia()
return@launch
}
val media = Media(VLCInstance.get(), uri)
VLCOptions.setMediaOptions(media, ctx, flags or mw.flags)
/* keeping only video during benchmark */
if (isBenchmark) {
......@@ -291,6 +295,11 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
}
}
private fun skipMedia() {
if (currentIndex != nextIndex) next()
else stop(false)
}
fun onServiceDestroyed() {
player.release()
}
......
......@@ -41,6 +41,7 @@ import android.util.Log;
import org.videolan.libvlc.util.AndroidUtil;
import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.BuildConfig;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.media.MediaUtils;
......@@ -325,9 +326,7 @@ public class FileUtils {
final ByteBuffer bb = ByteBuffer.allocateDirect((int)chunkSizeForFile);
int read;
long position = Math.max(size - HASH_CHUNK_SIZE, 0);
while ((read = fileChannel.read(bb, position)) > 0) {
position += read;
}
while ((read = fileChannel.read(bb, position)) > 0) position += read;
bb.flip();
tail = computeHashForChunk(bb);
return String.format("%016x", size + head + tail);
......@@ -343,8 +342,7 @@ public class FileUtils {
private static long computeHashForChunk(ByteBuffer buffer) {
final LongBuffer longBuffer = buffer.order(ByteOrder.LITTLE_ENDIAN).asLongBuffer();
long hash = 0;
while (longBuffer.hasRemaining())
hash += longBuffer.get();
while (longBuffer.hasRemaining()) hash += longBuffer.get();
return hash;
}
......@@ -363,20 +361,18 @@ public class FileUtils {
new String[]{MediaStore.MediaColumns.DISPLAY_NAME}, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
final String filename = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME)).replace("/", "");
Log.i(TAG, "Getting file " + filename + " from content:// URI");
if (BuildConfig.DEBUG) Log.i(TAG, "Getting file " + filename + " from content:// URI");
is = ctx.getContentResolver().openInputStream(data);
if (is == null) return data;
os = new FileOutputStream(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY + "/Download/" + filename);
final byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = is.read(buffer)) >= 0) {
os.write(buffer, 0, bytesRead);
}
while ((bytesRead = is.read(buffer)) >= 0) os.write(buffer, 0, bytesRead);
uri = AndroidUtil.PathToUri(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY + "/Download/" + filename);
}
} catch (Exception e) {
Log.e(TAG, "Couldn't download file from mail URI");
return data;
return null;
} finally {
Util.close(is);
Util.close(os);
......@@ -411,10 +407,10 @@ public class FileUtils {
// }
} catch (FileNotFoundException|IllegalArgumentException e) {
Log.e(TAG, "Couldn't understand the intent");
return data;
return null;
} catch (SecurityException e) {
Log.e(TAG, "Permission is no longer valid");
return data;
return null;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment