Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 49 additions & 13 deletions freedom-video-player/modules/playback-position.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,19 @@ if (!Date.now) {

// remove all AWS signatures from this video
var item = {
name: video_name,
name: video_name,abLoopPositions,
position: playPositions[video_name],
top_position: playTopPositions[video_name],
saw: typeof(sawVideo[video_name]) != "undefined" ? sawVideo[video_name] : false,
}

// add ab loop positions
if( abLoopPositions.hasOwnProperty(video_name) ) {
item.ab_start = abLoopPositions[video_name][0];
item.ab_end = abLoopPositions[video_name][1];
if( typeof abLoopPositions[video_name] != 'undefined' ) {
console.log('abLoopPositions', abLoopPositions[video_name]);

item.ab_start = abLoopPositions[video_name]['positions'][0];
item.ab_end = abLoopPositions[video_name]['positions'][1];
item.ab_active = abLoopPositions[video_name]['active'];
}

postDataPositions.push(item);
Expand Down Expand Up @@ -199,7 +202,14 @@ if (!Date.now) {
temp_saw_data[name] = postDataPositions[i].saw;

if( typeof(postDataPositions[i].ab_start) != "undefined" && typeof(postDataPositions[i].ab_end) != "undefined" ) {
temp_ab_loop_data[name] = [ postDataPositions[i].ab_start, postDataPositions[i].ab_end ];
temp_ab_loop_data[name] = {};

temp_ab_loop_data[name]['positions'] = [ postDataPositions[i].ab_start, postDataPositions[i].ab_end ];
temp_ab_loop_data[name]['active'] = postDataPositions[i].ab_active;
}

if( typeof(postDataPositions[i].ab_active != 'undefined') ) {

}
}

Expand Down Expand Up @@ -259,7 +269,7 @@ if (!Date.now) {
data_playlist_item = {};
}

// add / edit our video positions
// add / edit our video positionsab
for (var i in postDataPositions) {
if( !postDataPositions.hasOwnProperty(i) ) continue;

Expand Down Expand Up @@ -407,9 +417,24 @@ if (!Date.now) {

playPositions[video_id] = position;

// store ab loop positions as object
if( typeof abLoopPositions[video_id] == 'undefined' ) {
abLoopPositions[video_id] = {
positions: [0,5],
active: false
}
}

// check if abloop is active
if ( $root.hasClass('has-abloop') ) {
abLoopPositions[video_id].active = true;
} else {
abLoopPositions[video_id].active = false;
}

// check if we have a noUiSlider instance and AB loop is active
if ( typeof api.fv_noUiSlider != "undefined" && $root.find('.fv-player-ab.is-active').length ) {
abLoopPositions[video_id] = api.fv_noUiSlider.get();
abLoopPositions[video_id].positions = api.fv_noUiSlider.get();
}

// initialize top position variable with the already stored top position
Expand Down Expand Up @@ -629,6 +654,7 @@ if (!Date.now) {
playlist = is_playlist ? api.conf.playlist : [ api.conf.clip ],
playlist_external = jQuery('[rel='+jQuery(root).attr('id')+']');

// restore values from temp cookie for each video
for( var i in playlist ) {
if (!playlist.hasOwnProperty(i)) continue;

Expand All @@ -652,6 +678,7 @@ if (!Date.now) {
} else {
api.conf.clip.sources[0].position = position;
}

}

// Accept the new top position if there is none or if then new one is bigger
Expand All @@ -675,16 +702,25 @@ if (!Date.now) {

if( ab_loop ) {
if( is_playlist ) {
api.conf.playlist[i].sources[0].ab_start = ab_loop[0];
api.conf.playlist[i].sources[0].ab_end = ab_loop[1];
api.conf.playlist[i].sources[0].ab_start = ab_loop['positions'][0];
api.conf.playlist[i].sources[0].ab_end = ab_loop['positions'][1];
api.conf.playlist[i].sources[0].ab_active = ab_loop['active'];
} else {
api.conf.clip.sources[0].ab_start = ab_loop[0];
api.conf.clip.sources[0].ab_end = ab_loop[1];
api.conf.clip.sources[0].ab_start =ab_loop['positions'][0];
api.conf.clip.sources[0].ab_end = ab_loop['positions'][1];
api.conf.clip.sources[0].ab_active = ab_loop['active'];
}
}

}
abLoopPositions[video_id] = {
positions: [0,5],
active: false
};

// return postions & active state
abLoopPositions[video_id].positions = [ ab_loop['positions'][0], ab_loop['positions'][1] ];
abLoopPositions[video_id].active = ab_loop['active'];
}
}
}

// store saw after finish
Expand Down
2 changes: 1 addition & 1 deletion fv-player.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

global $fv_wp_flowplayer_ver;

$fv_wp_flowplayer_ver = '8.0.beta.5';
$fv_wp_flowplayer_ver = '8.0.beta.6';
$fv_wp_flowplayer_core_ver = '7.2.15';
include_once( dirname( __FILE__ ) . '/includes/extra-functions.php' );
if( file_exists( dirname( __FILE__ ) . '/includes/module.php' ) ) {
Expand Down
25 changes: 24 additions & 1 deletion models/player-position-save.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function plugin_update_database() {
legacy_video_id varchar(255) NOT NULL,
ab_start int(11) NOT NULL,
ab_end int(11) NOT NULL,
ab_active tinyint(1) NOT NULL,
last_updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
KEY user_id (user_id),
Expand Down Expand Up @@ -76,13 +77,15 @@ private function set_cache($user_id, $type) {
self::$cache[$user_id] = array();
}

// set cache for video data
if( $type == 'video') {
self::$cache[$user_id][$type] = $wpdb->get_results( $wpdb->prepare(
"SELECT video_id, last_position, top_position, finished, legacy_video_id, ab_start, ab_end FROM `{$wpdb->prefix}fv_player_user_video_positions` WHERE user_id = %d",
"SELECT video_id, last_position, top_position, finished, legacy_video_id, ab_start, ab_end, ab_active FROM `{$wpdb->prefix}fv_player_user_video_positions` WHERE user_id = %d",
$user_id
) );
}

// set cache for playlist data
if( $type == 'playlist' ) {
self::$cache[$user_id][$type] = $wpdb->get_results( $wpdb->prepare(
"SELECT player_id, item_index FROM `{$wpdb->prefix}fv_player_user_playlist_positions` WHERE user_id = %d",
Expand Down Expand Up @@ -370,6 +373,15 @@ public static function get_extensionless_file_name($path) {
return pathinfo($video_name, PATHINFO_FILENAME);
}

/**
* Set data for video item
*
* @param array $aItem
* @param int $index
* @param array $aArgs
*
* @return array
*/
public function set_last_positions( $aItem, $index, $aArgs ) {
global $fv_fp;
// we only use the first source to check for stored position,
Expand Down Expand Up @@ -423,13 +435,18 @@ public function set_last_positions( $aItem, $index, $aArgs ) {
foreach( $try AS $name ) {
$metaPositionStart = $this->get_video_position( get_current_user_id(), $name, 'ab_start' );
$metaPositionEnd = $this->get_video_position( get_current_user_id(), $name, 'ab_end' );
$metaPositionActive = $this->get_video_position( get_current_user_id(), $name, 'ab_active' );

// if the active value is set, but the start and end are not, then set them to 0
$aItem['sources'][0]['ab_active'] = $metaPositionActive;

// at least one of the values must be set and the start must be smaller than the end
if( ( $metaPositionStart || $metaPositionEnd ) && $metaPositionStart < $metaPositionEnd ) {
$aItem['sources'][0]['ab_start'] = $metaPositionStart;
$aItem['sources'][0]['ab_end'] = $metaPositionEnd;
break;
}

}

}
Expand Down Expand Up @@ -496,6 +513,12 @@ public function video_position_save() {
$this->delete_video_postion($uid, $name, 'ab_end');
}

if(!empty($record['ab_active'])) {
$this->set_video_position($uid, $name, 'ab_active', intval($record['ab_active']));
} else {
$this->delete_video_postion($uid, $name, 'ab_active');
}

// Did the user saw the full video?
if( !empty($record['saw']) && $record['saw'] == true ) {
$this->set_video_position($uid, $name, 'finished', 1);
Expand Down