halfway through implementing timestamps:

* still need to use the start position value stored in the PlayVideoActivity's Intent bundle, to set the VideoView using seekTo()
* need to test timestamp extraction regex, and possibly move it somewhere else
*need to find a better way to get the startPosition value to ActionBarHandler, which I thought used VideoInfo objects, but apparently doesn't
    * currently there is a small setStartPosition() method
This commit is contained in:
Adam Howard 2015-11-14 11:47:21 +00:00
parent b65263349e
commit b0182ed604
4 changed files with 28 additions and 2 deletions

View File

@ -48,6 +48,7 @@ public class ActionBarHandler {
private String videoTitle = "";
SharedPreferences defaultPreferences = null;
private int startPosition;
class FormatItemSelectListener implements ActionBar.OnNavigationListener {
@Override
@ -216,12 +217,18 @@ public class ActionBarHandler {
intent.putExtra(PlayVideoActivity.VIDEO_TITLE, videoTitle);
intent.putExtra(PlayVideoActivity.STREAM_URL, videoStreams[selectedStream].url);
intent.putExtra(PlayVideoActivity.VIDEO_URL, websiteUrl);
activity.startActivity(intent);
intent.putExtra(PlayVideoActivity.START_POSITION, startPosition);
activity.startActivity(intent); //also HERE !!!
}
}
// --------------------------------------------
}
public void setStartPosition(int startPositionSeconds)
{
this.startPosition = startPositionSeconds;
}
public void downloadVideo() {
if(!videoTitle.isEmpty()) {
String videoSuffix = "." + MediaFormat.getSuffixById(videoStreams[selectedStream].format);

View File

@ -52,6 +52,7 @@ public class PlayVideoActivity extends AppCompatActivity {
public static final String STREAM_URL = "stream_url";
public static final String VIDEO_TITLE = "video_title";
private static final String POSITION = "position";
public static final String START_POSITION = "start_position";
private static final long HIDING_DELAY = 3000;
private static final long TAB_HIDING_DELAY = 100;

View File

@ -50,6 +50,7 @@ public class VideoInfo {
public VideoInfoItem nextVideo = null;
public VideoInfoItem[] relatedVideos = null;
public int videoAvailableStatus = VIDEO_AVAILABLE;
public int startPosition = 0;//in seconds
private static final String TAG = VideoInfo.class.toString();

View File

@ -169,6 +169,23 @@ public class YoutubeExtractor implements Extractor {
Document doc = Jsoup.parse(site, siteUrl);
videoInfo.id = matchGroup1("v=([0-9a-zA-Z_-]{11})", siteUrl);
String timeStamp = matchGroup1("((#|&)t=\\d{0,3}h?\\d{0,3}m?\\d{1,3}s)", siteUrl);
Log.i(TAG, "time stamp:"+timeStamp);
//videoInfo.startPosition
//TODO: test this!
if(timeStamp.length() > 0) {
String secondsString = matchGroup1("(\\d{1,3})s", timeStamp);
String minutesString = matchGroup1("(\\d{1,3})m", timeStamp);
String hoursString = matchGroup1("(\\d{1,3})h", timeStamp);
int seconds = (secondsString.length() > 0 ? Integer.parseInt(secondsString) : 0);
int minutes = (minutesString.length() > 0 ? Integer.parseInt(minutesString) : 0);
int hours = (hoursString.length() > 0 ? Integer.parseInt(hoursString) : 0);
videoInfo.startPosition = seconds + (60*minutes) + (3600*hours);//don't trust BODMAS!
//the ordering varies internationally
}//else, leave videoInfo.startPosition as default 0
videoInfo.age_limit = 0;
videoInfo.webpage_url = siteUrl;
@ -410,7 +427,7 @@ public class YoutubeExtractor implements Extractor {
Element img = li.select("img").first();
info.thumbnail_url = img.attr("abs:src");
// Sometimes youtube sends links to gif files witch somehow seam to not exist
// Sometimes youtube sends links to gif files which somehow sesm to not exist
// anymore. Items with such gif also offer a secondary image source. So we are going
// to use that if we caught such an item.
if(info.thumbnail_url.contains(".gif")) {