Mancent Posted February 27, 2014 Share Posted February 27, 2014 (edited) Ok this is what I got so far, if I set this to $(document).ready(function(){ $('#source_videos button').ready(function(){ convertVideo($(this)); }); });I thought it would just be as if it was the same as the click, but its not and it always fails.I am trying to make the page function automatically with no click at all, but just if the page is called, it then starts to convert the file. can any one help with this? <?php require 'config.php'; require 'functions.php'; $uid = "1000"; ?> <script src="http://code.jquery.c...in.js"></script> <script src="./js/jquery.percentageloader-0.1.js"></script> <script src="./js/jquery.timer.js"></script> <?php foreach(_source_files() as $file) { $ext = pathinfo($file, PATHINFO_EXTENSION); }?> <script>jsNS = {'base_url' : '<?php echo BASE_URL; ?>', 'post_url' : '<?php echo POST_URL.'?uid='.$uid.'&ext='.$ext.''; ?>'}</script> <script> (function($){ var fkey, topLoader, startstopTimer, startstopCurrent = 0;; var fkeys=[]; // Padding function function pad(number, length) { var str = '' + number; while (str.length < length) {str = '0' + str;} return str; } // Initialize the progress loader $(function(){ topLoader = $("#progress").percentageLoader({ width : 150, height : 150, controllable : false, value : '00:00:00', progress : 0, onProgressUpdate : function(val) { topLoader.setValue(Math.round(val * 100.0)); } }); }); function convertVideo(el){ var filename = el.data('filename'); fkey = el.data('fkey'); var params = $('#ffmpeg_params').val(); fkeys.push(fkey); $.ajax(jsNS.post_url, { type : 'POST', dataType : 'json', async : false, data : { 'filename' : filename, 'fkey' : fkey, 'type' : 'convert', 'params' : params }, success : function(data){ startPolling(data); }, error : function(){ alert('Request failed!'); } }); } function pollStatus(fkey){ var statusData; $.ajax(jsNS.post_url, { type : 'POST', dataType : 'json', async : false, data : { 'fkey' : fkey, 'type' : 'status' }, success : function(data){ statusData = data; }, error : function(){ alert('Polling failed!'); statusData = false; } }); return statusData; } function startPolling(data){ var currentTime, totalTime, hrCurrentTime, hrTotalTime, statData, intPoll, timer, count; count = 0; currentTime = data.time_encoded; totalTime = data.time_total; timer = $.timer(function() { var min = parseInt(startstopCurrent/6000); var sec = parseInt(startstopCurrent/100)-(min*60); var micro = pad(startstopCurrent-(sec*100)-(min*6000),2); var output = "00"; if(min > 0) {output = pad(min,2);} topLoader.setValue(output+":"+pad(sec,2)+":"+micro); startstopCurrent+=7; }, 70, true); timer.play(); intPoll = setInterval(function(){ if( currentTime < totalTime ) { statData = pollStatus(fkey, currentTime); //console.log(statData); if( !statData ){ alert('Bad data!'); //console.log(statData); clearInterval(intPoll); return false; } currentTime = statData.time_encoded; totalTime = statData.time_total; hrCurrentTime = statData.time_encoded_min; hrTotalTime = statData.time_total_min; topLoader.setProgress(currentTime / totalTime); } else { timer.stop(); clearInterval(intPoll); //lets clean up the data delete the old file and move the new file to location then update the database $.post("../../rfi.php", { name:"Donald Duck", city:"Duckburg" }, function(data,status){ //alert("Data: " + data + "\nStatus: " + status); alert('Finished!'); }); } },1000); } $(document).ready(function(){ $('#source_videos button').click(function(){ convertVideo($(this)); }); }); })(jQuery); </script> <div id="progress"></div> <ul id="source_videos"> <button type="text" data-filename="<?php echo $file; ?>" data-fkey="<?php echo hash('crc32', time() . $file, false); ?>"> </button> </ul> <?php if(($ext == "wav") || ($ext == "mpeg") || ($ext == "mp3")) { ?> <textarea cols="120" rows="3" id="ffmpeg_params" style="visibility:hidden">-acodec mp3 -ac 2 -ab 128 </textarea> <?php } else if(($ext == "avi") || ($ext == "flv") || ($ext == "mkv") || ($ext == "wmv") || ($ext == "mov") || ($ext == "mp4") || ($ext == "3gp")) { ?> <textarea cols="120" rows="3" id="ffmpeg_params" style="visibility:hidden">-acodec libvo_aacenc -ac 2 -ab 128 -ar 22050 -s 900x500 -vcodec libx264 -fpre "<?php echo BASE_PATH; ?>ffmpeg\presets\libx264-ipod640.ffpreset" -b 600k -f mp4 -threads 0</textarea> <?php } ?> <!-- Makes mp4 video nice qulity -acodec libvo_aacenc -ac 2 -ab 128 -ar 22050 -s 900x500 -vcodec libx264 -fpre "ffmpeg\presets\libx264-ipod640.ffpreset" -b 600k -f mp4 -threads 0 Makes mp3 audio nice qulity -acodec mp3 -ac 2 -ab 128 todo find ogg for oprea browser support command line for oga audio and ogv video. --> Edited February 27, 2014 by Mancent Quote Link to comment https://forums.phpfreaks.com/topic/286585-can-i-get-soem-help-with-loading-a-script-onlond-that-has-vars/ Share on other sites More sharing options...
Mancent Posted February 27, 2014 Author Share Posted February 27, 2014 (edited) this right here <ul id="source_videos"> <button type="text" data-filename="<?php echo $file; ?>" data-fkey="<?php echo hash('crc32', time() . $file, false); ?>"> </button> </ul> works just fine when the user click on the button, but I am trying to make it so it is auto no click is needed. and that's running this line right here $(document).ready(function(){ $('#source_videos button').click(function(){ convertVideo($(this)); }); }); so I thought it would be easy enough to just make it auto by using the ready function not the click $(document).ready(function(){ $('#source_videos button').ready(function(){ convertVideo($(this)); }); }); but doing that I always get a error. in the convertVideo function error message. Edited February 27, 2014 by Mancent Quote Link to comment https://forums.phpfreaks.com/topic/286585-can-i-get-soem-help-with-loading-a-script-onlond-that-has-vars/#findComment-1470955 Share on other sites More sharing options...
Solution kicken Posted February 27, 2014 Solution Share Posted February 27, 2014 Just call your convertVideo function from the document ready function. Eg: $(document).ready(function(){ convertVideo($('#source_videos button')); }); Quote Link to comment https://forums.phpfreaks.com/topic/286585-can-i-get-soem-help-with-loading-a-script-onlond-that-has-vars/#findComment-1470960 Share on other sites More sharing options...
Mancent Posted February 27, 2014 Author Share Posted February 27, 2014 awesome. thank you helped much. Quote Link to comment https://forums.phpfreaks.com/topic/286585-can-i-get-soem-help-with-loading-a-script-onlond-that-has-vars/#findComment-1470973 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.