<commit_before>﻿/*
 *  MP3 Flashbock
 *  An elegant MP3 Flash fallback when HTML5 audio is not supported
 *
 *  Copyright 2012, <NAME> (http://mbrooks.info)
 *  Licensed under the MIT license:
 *  http://www.opensource.org/licenses/mit-license.php
 *
 *  Dependencies:
 *    Flash AS3
 */

import flash.events.Event;
import flash.events.ProgressEvent;
import flash.media.Sound;
import flash.media.SoundChannel;

// enable external callbacks
ExternalInterface.addCallback('player', soundPlayer);

// import flashVars
var param:Object = LoaderInfo(this.root.loaderInfo).parameters;

// register globals
var isLoaded:Boolean  = false;
var isPlaying:Boolean = false;
var startTime:Number  = 0.00;
var soundChannel:SoundChannel;
var soundFile:Sound;

/*
 * Initialize sound object
 */
(function init() {
	soundFile = new Sound();
	soundFile.load(new URLRequest(param.file0));
	soundFile.addEventListener(Event.COMPLETE, loadComplete);
	soundFile.addEventListener(ProgressEvent.PROGRESS, loadProgress);
	soundFile.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
})();

/*
 * Callbacks when loading files; return progress as a percent
 */
function loadProgress(e:Event) {
	if (soundFile && soundFile.length > 0) {
		var percent:Number = Math.floor( (soundFile.bytesLoaded * 100) / soundFile.bytesTotal);
		ExternalInterface.call('loadProgress', percent);
		isLoaded = false;
	}
}

function loadComplete(e:Event) {
	if (soundFile && soundFile.length > 0) {
		soundFile.removeEventListener(Event.COMPLETE, loadComplete);
		ExternalInterface.call('loadComplete');
		isLoaded = true;
	}
}

/*
 * Callbacks when playing MP3s; returns duration and percent as function arguments
 */
function playProgress(e:Event) {
	if (isLoaded) {
		var minutes:uint    = Math.floor(soundChannel.position / 1000  / 60);
		var seconds:uint    = Math.floor(soundChannel.position / 1000) % 60;
		var duration:String = minutes + ':' + seconds;
		var loaded:Number   = soundFile.bytesLoaded  / soundFile.bytesTotal;
		var percent:Number  = (soundChannel.position / soundFile.length * loaded);
		ExternalInterface.call('playProgress', duration, percent);
		isPlaying = true;
	}
}

function playComplete(e:Event) {
	if (isPlaying) {
		ExternalInterface.call('playComplete');
		isPlaying = false;
	}
}

/*
 * MP3 player controls: Play, Pause, and Stop
 */
function soundPlayer(action):void {
	if (!isLoaded) { return }

	switch(action) {
		case 'play' :
			if (isPlaying) { return }
			isPlaying = true;
			soundChannel = soundFile.play(startTime);
			//addEventListener(Event.ENTER_FRAME, playProgress);
		break;

		case 'pause' :<commit_msg>Renamed Javascript external functions<commit_after>﻿/*
 *  MP3 Flashbock
 *  An elegant MP3 Flash fallback when HTML5 audio is not supported
 *
 *  Copyright 2012, <NAME> (http://mbrooks.info)
 *  Licensed under the MIT license:
 *  http://www.opensource.org/licenses/mit-license.php
 *
 *  Dependencies:
 *    Flash AS3
 */

import flash.events.Event;
import flash.events.ProgressEvent;
import flash.media.Sound;
import flash.media.SoundChannel;

// enable external callbacks
ExternalInterface.addCallback('player', soundPlayer);

// import flashVars
var param:Object = LoaderInfo(this.root.loaderInfo).parameters;

// register globals
var isLoaded:Boolean  = false;
var isPlaying:Boolean = false;
var startTime:Number  = 0.00;
var soundChannel:SoundChannel;
var soundFile:Sound;

/*
 * Initialize sound object
 */
(function init() {
	soundFile = new Sound();
	soundFile.load(new URLRequest(param.file0));
	soundFile.addEventListener(Event.COMPLETE, loadComplete);
	soundFile.addEventListener(ProgressEvent.PROGRESS, loadProgress);
	soundFile.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
})();

/*
 * Callbacks when loading files; return progress as a percent
 */
function loadProgress(e:Event) {
	if (soundFile && soundFile.length > 0) {
		var percent:Number = Math.floor( (soundFile.bytesLoaded * 100) / soundFile.bytesTotal);
		ExternalInterface.call('$.fn.loadProgress', percent);
		isLoaded = false;
	}
}

function loadComplete(e:Event) {
	if (soundFile && soundFile.length > 0) {
		soundFile.removeEventListener(Event.COMPLETE, loadComplete);
		ExternalInterface.call('$.fn.loadComplete');
		isLoaded = true;
	}
}

/*
 * Callbacks when playing MP3s; returns duration and percent as function arguments
 */
function playProgress(e:Event) {
	if (isLoaded) {
		var minutes:uint    = Math.floor(soundChannel.position / 1000  / 60);
		var seconds:uint    = Math.floor(soundChannel.position / 1000) % 60;
		var duration:String = minutes + ':' + seconds;
		var loaded:Number   = soundFile.bytesLoaded  / soundFile.bytesTotal;
		var percent:Number  = (soundChannel.position / soundFile.length * loaded);
		ExternalInterface.call('$.fn.playProgress', duration, percent);
		isPlaying = true;
	}
}

function playComplete(e:Event) {
	if (isPlaying) {
		ExternalInterface.call('$.fn.playComplete');
		isPlaying = false;
	}
}

/*
 * MP3 player controls: Play, Pause, and Stop
 */
function soundPlayer(action):void {
	if (!isLoaded) { return }

	switch(action) {
		case 'play' :
			if (isPlaying) { return }
			isPlaying = true;
			soundChannel = soundFile.play(startTime);
			addEventListener(Event.ENTER_FRAME, playProgress);
		break;

		case 'pause' :
{'fraction_non_alphanumeric': 0.12428734321550741, 'fraction_numerical': 0.01178259217027746, 'mean_word_length': 4.610874200426439, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4285221', 'n_tokens_mistral': 1727, 'n_tokens_neox': 1613, 'n_words': 381}