<commit_before>var session = null;
var increment = 0;
var progress = 0;
var currentMediaSession;

$( document ).ready(function(){
  document.getElementById("progress").addEventListener('mouseup', seekMedia);
  document.getElementById("progress").addEventListener('mouseenter', showTime);
  document.getElementById("progress").addEventListener('mouseleave', hideTime);
  var loadCastInterval = setInterval(function(){
    if (chrome.cast.isAvailable) 
    {
      console.log('Cast has loaded.');
      clearInterval(loadCastInterval);
      initializeCastApi();
    } 
    else 
    {
      console.log('Unavailable');
    }
  }, 1000);
});


function initializeCastApi() 
{
  var applicationID = chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID;
  var sessionRequest = new chrome.cast.SessionRequest(applicationID);
  var apiConfig = new chrome.cast.ApiConfig(sessionRequest, sessionListener, receiverListener);
  chrome.cast.initialize(apiConfig, onInitSuccess, onInitError);
}

function sessionListener(e) 
{
  session = e;
  console.log('New session');
  if (session.media.length !== 0) 
  {
    console.log('Found ' + session.media.length + ' sessions.');
  }
}

function receiverListener(e) {
  if( e == 'available' ) 
  {
    console.log("Chromecast was found on the network.");
    launchApp();
  }
  else 
  {
    console.log("There are no Chromecasts available.");
  }
}

function onInitSuccess() 
{
  console.log("Initialization succeeded");
}

function onInitError() 
{
  console.log("Initialization failed");
}

$('#castme').click(function()
{
  launchApp();
});

$('#pause').click(function()
{
  if(!session || !currentMediaSession) {
    return;
  }
  
  currentMediaSession.pause(null, pauseSuccess, playPauseFailure);
});

function pauseSuccess()
{
  console.log("Pause Success");
  $('#pause').addClass("hidden");
  $('#play').removeClass("hidden");
  increment = 0;
}

function playPauseFailure()
{
  console.log("Pause Failure");
}

$('#play').click(function()
{
  if(!session || !currentMediaSession) {
    return;
  }
  
  currentMediaSession.play(null, playSuccess, playPauseFailure);
});

function playSuccess()
{
  console.log("Play Success");
  $('#play').addClass("hidden");
  $('#pause').removeClass("hidden");
  var tt = mediaSession.media.duration;
  increment = (1/tt)*100;
}

function launchApp() 
{
  console.log("Launching the Chromecast App...");
  chrome.cast.requestSession(onRequestSessionSuccess, onLaunchError);
}

function onRequestSessionSuccess(e) 
{
  console.log("Successfully created session: " + e.sessionId);
  session = e;
}

function onLaunchError() 
{
  console.log("Error connecting to the Chromecast.");
}

function onRequestSessionSuccess(e) 
{
  console.log("Successfully created session: " + e.sessionId);
  session = e;
  loadMedia();
}

function loadMedia() 
{
  if (!session) 
  {
    console.log("No session.");
    return;
  }

  var mediaInfo = new chrome.cast.media.MediaInfo(videoLink);
  mediaInfo.contentType = 'video/mp4';

  var request = new chrome.cast.media.LoadRequest(mediaInfo);
  request.autoplay = true;

  session.loadMedia(request, onLoadSuccess, onLoadError);
}

function onLoadSuccess(mediaSession) {
  console.log('Successfully loaded.');
  playSuccess();
  currentMediaSession = mediaSession;
  mediaSession.addUpdateListener(onMediaStatusUpdate);
  var tt = mediaSession.media.duration;
  increment = (1/tt)*100;
  console.log(increment, mediaSession.media.duration); 
  updateProgressBar();
}

function updateProgressBar()
{
  document.getElementById('progressBar').style.width= (progress) +'%';
  var timeLeftInSecs = progress/increment;
  var hours = Math.floor(timeLeftInSecs / 3600);
  var minutes = Math.floor(timeLeftInSecs / 60);
  var seconds = timeLeftInSecs - hours * 3600 - minutes * 60;
  if(!isNaN(timeLeftInSecs))
  {
    document.getElementById('timeleft').innerHTML = ((hours < 10) ? ('0' + hours) : hours) + ':' + ((minutes<10) ? ('0' + minutes) : minutes) + ':' + ((seconds<10) ? ('0'+seconds.toFixed(3)) : seconds.toFixed(3));
  }
  else
  {
    document.getElementById('timeleft').innerHTML = '00:00:00.000';
  }
  if(progress < 100 && increment !== 0)
  {
    progress = progress + increment;
    setTimeout(updateProgressBar,1000);
  }<commit_msg>fix bug in playSucess function<commit_after>var session = null;
var increment = 0;
var progress = 0;
var currentMediaSession;

$( document ).ready(function(){
  document.getElementById("progress").addEventListener('mouseup', seekMedia);
  document.getElementById("progress").addEventListener('mouseenter', showTime);
  document.getElementById("progress").addEventListener('mouseleave', hideTime);
  var loadCastInterval = setInterval(function(){
    if (chrome.cast.isAvailable) 
    {
      console.log('Cast has loaded.');
      clearInterval(loadCastInterval);
      initializeCastApi();
    } 
    else 
    {
      console.log('Unavailable');
    }
  }, 1000);
});


function initializeCastApi() 
{
  var applicationID = chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID;
  var sessionRequest = new chrome.cast.SessionRequest(applicationID);
  var apiConfig = new chrome.cast.ApiConfig(sessionRequest, sessionListener, receiverListener);
  chrome.cast.initialize(apiConfig, onInitSuccess, onInitError);
}

function sessionListener(e) 
{
  session = e;
  console.log('New session');
  if (session.media.length !== 0) 
  {
    console.log('Found ' + session.media.length + ' sessions.');
  }
}

function receiverListener(e) {
  if( e == 'available' ) 
  {
    console.log("Chromecast was found on the network.");
    launchApp();
  }
  else 
  {
    console.log("There are no Chromecasts available.");
  }
}

function onInitSuccess() 
{
  console.log("Initialization succeeded");
}

function onInitError() 
{
  console.log("Initialization failed");
}

$('#castme').click(function()
{
  launchApp();
});

$('#pause').click(function()
{
  if(!session || !currentMediaSession) {
    return;
  }
  
  currentMediaSession.pause(null, pauseSuccess, playPauseFailure);
});

function pauseSuccess()
{
  console.log("Pause Success");
  $('#pause').addClass("hidden");
  $('#play').removeClass("hidden");
  increment = 0;
}

function playPauseFailure()
{
  console.log("Pause Failure");
}

$('#play').click(function()
{
  if(!session || !currentMediaSession) {
    return;
  }
  
  currentMediaSession.play(null, playSuccess, playPauseFailure);
});

function playSuccess()
{
  console.log("Play Success");
  $('#play').addClass("hidden");
  $('#pause').removeClass("hidden");
  var tt = currentMediaSession.media.duration;
  increment = (1/tt)*100;
}

function launchApp() 
{
  console.log("Launching the Chromecast App...");
  chrome.cast.requestSession(onRequestSessionSuccess, onLaunchError);
}

function onRequestSessionSuccess(e) 
{
  console.log("Successfully created session: " + e.sessionId);
  session = e;
}

function onLaunchError() 
{
  console.log("Error connecting to the Chromecast.");
}

function onRequestSessionSuccess(e) 
{
  console.log("Successfully created session: " + e.sessionId);
  session = e;
  loadMedia();
}

function loadMedia() 
{
  if (!session) 
  {
    console.log("No session.");
    return;
  }

  var mediaInfo = new chrome.cast.media.MediaInfo(videoLink);
  mediaInfo.contentType = 'video/mp4';

  var request = new chrome.cast.media.LoadRequest(mediaInfo);
  request.autoplay = true;

  session.loadMedia(request, onLoadSuccess, onLoadError);
}

function onLoadSuccess(mediaSession) {
  console.log('Successfully loaded.');
  currentMediaSession = mediaSession;
  playSuccess();
  mediaSession.addUpdateListener(onMediaStatusUpdate);
  var tt = mediaSession.media.duration;
  increment = (1/tt)*100;
  console.log(increment, mediaSession.media.duration); 
  updateProgressBar();
}

function updateProgressBar()
{
  document.getElementById('progressBar').style.width= (progress) +'%';
  var timeLeftInSecs = progress/increment;
  var hours = Math.floor(timeLeftInSecs / 3600);
  var minutes = Math.floor(timeLeftInSecs / 60);
  var seconds = timeLeftInSecs - hours * 3600 - minutes * 60;
  if(!isNaN(timeLeftInSecs))
  {
    document.getElementById('timeleft').innerHTML = ((hours < 10) ? ('0' + hours) : hours) + ':' + ((minutes<10) ? ('0' + minutes) : minutes) + ':' + ((seconds<10) ? ('0'+seconds.toFixed(3)) : seconds.toFixed(3));
  }
  else
  {
    document.getElementById('timeleft').innerHTML = '00:00:00.000';
  }
  if(progress < 100 && increment !== 0)
  {
    progress = progress + increment;
    setTimeout(updateProgressBar,1000);
  }
{'fraction_non_alphanumeric': 0.15478424015009382, 'fraction_numerical': 0.013367729831144466, 'mean_word_length': 4.563600782778865, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1618568', 'n_tokens_mistral': 2752, 'n_tokens_neox': 2656, 'n_words': 492}