Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Geoffrey Métais
VLC-Android
Commits
85eca846
Commit
85eca846
authored
May 03, 2018
by
Geoffrey Métais
Browse files
Skip media loading if uri is invalid
parent
022e12e5
Changes
2
Hide whitespace changes
Inline
Side-by-side
vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
View file @
85eca846
...
...
@@ -254,11 +254,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
)
setStartTime
(
media
,
mw
)
VLCOptions
.
setMediaOptions
(
media
,
ctx
,
flags
or
mw
.
flags
)
/* keeping only video during benchmark */
...
...
@@ -299,6 +303,11 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
}
}
private
fun
skipMedia
()
{
if
(
currentIndex
!=
nextIndex
)
next
()
else
stop
(
false
)
}
fun
onServiceDestroyed
()
{
player
.
release
()
}
...
...
@@ -670,8 +679,8 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
}
MediaPlayer
.
Event
.
EncounteredError
->
{
service
.
showToast
(
service
.
getString
(
R
.
string
.
invalid_location
,
getCurrentMedia
()
?.
getLocation
()
?:
""
),
Toast
.
LENGTH_SHORT
)
R
.
string
.
invalid_location
,
getCurrentMedia
()
?.
getLocation
()
?:
""
),
Toast
.
LENGTH_SHORT
)
next
()
}
}
...
...
vlc-android/src/org/videolan/vlc/util/FileUtils.java
View file @
85eca846
...
...
@@ -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
;
...
...
@@ -323,9 +324,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
);
...
...
@@ -341,8 +340,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
;
}
...
...
@@ -361,20 +359,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
);
...
...
@@ -404,10 +400,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
;
}
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment