Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
Casanowow Life for love
VLC-Android
Commits
441a48ac
Commit
441a48ac
authored
Aug 07, 2012
by
Sébastien Toque
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Save & Restore last position for each video media
parent
bde0509e
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
22 deletions
+67
-22
vlc-android/src/org/videolan/vlc/DatabaseManager.java
vlc-android/src/org/videolan/vlc/DatabaseManager.java
+39
-0
vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
...android/src/org/videolan/vlc/gui/PreferencesActivity.java
+0
-1
vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
...roid/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+15
-11
vlc-android/src/org/videolan/vlc/gui/video/VideoListFragment.java
...oid/src/org/videolan/vlc/gui/video/VideoListFragment.java
+4
-2
vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
...d/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+9
-8
No files found.
vlc-android/src/org/videolan/vlc/DatabaseManager.java
View file @
441a48ac
...
...
@@ -358,6 +358,41 @@ public class DatabaseManager {
return
medias
;
}
public
synchronized
HashMap
<
String
,
Long
>
getVideoTimes
(
Context
context
)
{
Cursor
cursor
;
HashMap
<
String
,
Long
>
times
=
new
HashMap
<
String
,
Long
>();
int
chunk_count
=
0
;
int
count
=
0
;
do
{
count
=
0
;
cursor
=
mDb
.
rawQuery
(
String
.
format
(
Locale
.
US
,
"SELECT %s,%s FROM %s WHERE %s=%d LIMIT %d OFFSET %d"
,
MEDIA_LOCATION
,
//0 string
MEDIA_TIME
,
//1 long
MEDIA_TABLE_NAME
,
MEDIA_TYPE
,
Media
.
TYPE_VIDEO
,
CHUNK_SIZE
,
chunk_count
*
CHUNK_SIZE
),
null
);
if
(
cursor
.
moveToFirst
())
{
do
{
String
location
=
cursor
.
getString
(
0
);
long
time
=
cursor
.
getLong
(
1
);
times
.
put
(
location
,
time
);
count
++;
}
while
(
cursor
.
moveToNext
());
}
cursor
.
close
();
chunk_count
++;
}
while
(
count
==
CHUNK_SIZE
);
return
times
;
}
public
synchronized
Media
getMedia
(
Context
context
,
String
location
)
{
Cursor
cursor
;
...
...
@@ -437,6 +472,10 @@ public class DatabaseManager {
values
.
put
(
MEDIA_PICTURE
,
new
byte
[
1
]);
}
break
;
case
MEDIA_TIME:
if
(
object
!=
null
)
values
.
put
(
MEDIA_TIME
,
(
Long
)
object
);
break
;
default
:
return
;
}
...
...
vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
View file @
441a48ac
...
...
@@ -47,7 +47,6 @@ public class PreferencesActivity extends PreferenceActivity {
public
final
static
String
NAME
=
"VlcSharedPreferences"
;
public
final
static
String
LAST_MEDIA
=
"LastMedia"
;
public
final
static
String
LAST_TIME
=
"LastTime"
;
@SuppressWarnings
(
"deprecation"
)
@Override
...
...
vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
View file @
441a48ac
...
...
@@ -21,6 +21,7 @@
package
org.videolan.vlc.gui.video
;
import
java.util.Comparator
;
import
java.util.HashMap
;
import
org.videolan.vlc.Media
;
import
org.videolan.vlc.R
;
...
...
@@ -46,7 +47,6 @@ public class VideoListAdapter extends ArrayAdapter<Media>
public
final
static
int
SORT_BY_LENGTH
=
1
;
private
int
mSortDirection
=
1
;
private
int
mSortBy
=
SORT_BY_TITLE
;
private
long
mLastTime
;
private
String
mLastMRL
;
public
VideoListAdapter
(
Context
context
)
{
...
...
@@ -63,9 +63,15 @@ public class VideoListAdapter extends ArrayAdapter<Media>
}
}
public
void
setLastMedia
(
long
lastTime
,
String
lastMRL
)
{
mLastTime
=
lastTime
;
mLastMRL
=
lastTime
>
0
?
lastMRL
:
null
;
public
void
setLastMedia
(
String
lastMRL
,
HashMap
<
String
,
Long
>
times
)
{
mLastMRL
=
lastMRL
;
// update times
for
(
int
i
=
0
;
i
<
getCount
();
++
i
)
{
Media
media
=
getItem
(
i
);
Long
time
=
times
.
get
(
media
.
getLocation
());
if
(
time
!=
null
)
media
.
setTime
(
time
);
}
}
public
void
sortBy
(
int
sortby
)
{
...
...
@@ -148,17 +154,15 @@ public class VideoListAdapter extends ArrayAdapter<Media>
holder
.
thumbnail
.
setImageBitmap
(
thumbnail
);
}
if
(
media
.
getLocation
().
equals
(
mLastMRL
)
)
{
holder
.
title
.
setTextColor
(
0xFFF48B00
/* ORANGE */
);
holder
.
title
.
setTextColor
(
media
.
getLocation
().
equals
(
mLastMRL
)
?
0xFFF48B00
/* ORANGE */
:
Color
.
WHITE
);
long
lastTime
=
media
.
getTime
();
if
(
lastTime
>
0
)
{
holder
.
subtitle
.
setText
(
String
.
format
(
"%s / %s - %dx%d"
,
Util
.
millisToString
(
mL
astTime
),
Util
.
millisToString
(
l
astTime
),
Util
.
millisToString
(
media
.
getLength
()),
media
.
getWidth
(),
media
.
getHeight
()));
}
else
{
holder
.
title
.
setTextColor
(
Color
.
WHITE
);
else
{
holder
.
subtitle
.
setText
(
String
.
format
(
"%s - %dx%d"
,
Util
.
millisToString
(
media
.
getLength
()),
media
.
getWidth
(),
media
.
getHeight
()));
...
...
vlc-android/src/org/videolan/vlc/gui/video/VideoListFragment.java
View file @
441a48ac
...
...
@@ -20,11 +20,13 @@
package
org.videolan.vlc.gui.video
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.concurrent.BrokenBarrierException
;
import
java.util.concurrent.CyclicBarrier
;
import
org.videolan.vlc.AudioServiceController
;
import
org.videolan.vlc.DatabaseManager
;
import
org.videolan.vlc.Media
;
import
org.videolan.vlc.MediaLibrary
;
import
org.videolan.vlc.R
;
...
...
@@ -105,8 +107,8 @@ public class VideoListFragment extends SherlockListFragment implements ISortable
//Get & highlight the last media
SharedPreferences
preferences
=
getActivity
().
getSharedPreferences
(
PreferencesActivity
.
NAME
,
Context
.
MODE_PRIVATE
);
String
lastPath
=
preferences
.
getString
(
PreferencesActivity
.
LAST_MEDIA
,
null
);
long
lastT
ime
=
prefere
nce
s
.
get
Long
(
PreferencesActivity
.
LAST_TIME
,
0
);
mVideoAdapter
.
setLastMedia
(
last
Time
,
lastPath
);
HashMap
<
String
,
Long
>
t
ime
s
=
DatabaseManager
.
getInsta
nce
(
get
Activity
()).
getVideoTimes
(
getActivity
()
);
mVideoAdapter
.
setLastMedia
(
last
Path
,
times
);
mVideoAdapter
.
notifyDataSetChanged
();
mMediaLibrary
.
addUpdateHandler
(
mHandler
);
super
.
onResume
();
...
...
vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
View file @
441a48ac
...
...
@@ -26,9 +26,11 @@ import java.lang.reflect.Method;
import
java.net.URLDecoder
;
import
org.videolan.vlc.AudioServiceController
;
import
org.videolan.vlc.DatabaseManager
;
import
org.videolan.vlc.EventManager
;
import
org.videolan.vlc.LibVLC
;
import
org.videolan.vlc.LibVlcException
;
import
org.videolan.vlc.Media
;
import
org.videolan.vlc.R
;
import
org.videolan.vlc.Util
;
import
org.videolan.vlc.WeakHandler
;
...
...
@@ -306,8 +308,11 @@ public class VideoPlayerActivity extends Activity {
SharedPreferences
preferences
=
getSharedPreferences
(
PreferencesActivity
.
NAME
,
MODE_PRIVATE
);
SharedPreferences
.
Editor
editor
=
preferences
.
edit
();
editor
.
putString
(
PreferencesActivity
.
LAST_MEDIA
,
mLocation
);
editor
.
putLong
(
PreferencesActivity
.
LAST_TIME
,
time
);
editor
.
commit
();
DatabaseManager
.
getInstance
(
this
).
updateMedia
(
mLocation
,
DatabaseManager
.
mediaColumn
.
MEDIA_TIME
,
time
);
}
super
.
onPause
();
}
...
...
@@ -999,10 +1004,7 @@ public class VideoPlayerActivity extends Activity {
private
void
load
()
{
mLocation
=
null
;
String
title
=
null
;
String
lastLocation
=
null
;
long
lastTime
=
0
;
boolean
dontParse
=
false
;
SharedPreferences
preferences
=
getSharedPreferences
(
PreferencesActivity
.
NAME
,
MODE_PRIVATE
);
if
(
getIntent
().
getAction
()
!=
null
&&
getIntent
().
getAction
().
equals
(
Intent
.
ACTION_VIEW
))
{
...
...
@@ -1019,10 +1021,9 @@ public class VideoPlayerActivity extends Activity {
mSurface
.
setKeepScreenOn
(
true
);
// restore last position
lastLocation
=
preferences
.
getString
(
PreferencesActivity
.
LAST_MEDIA
,
null
);
lastTime
=
preferences
.
getLong
(
PreferencesActivity
.
LAST_TIME
,
0
);
if
(
lastTime
>
0
&&
mLocation
.
equals
(
lastLocation
))
mLibVLC
.
setTime
(
lastTime
);
Media
media
=
DatabaseManager
.
getInstance
(
this
).
getMedia
(
this
,
mLocation
);
if
(
media
!=
null
&&
media
.
getTime
()
>
0
)
mLibVLC
.
setTime
(
media
.
getTime
());
try
{
title
=
URLDecoder
.
decode
(
mLocation
,
"UTF-8"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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