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