解决方案 »
- php调用Microsoft Speech SDK
- 关于用户登陆WAP网站,地区的判断?
- PHP 向页面输出javascript代码
- 正则表达式 截取字符
- 小站上线,帮助测试,进来有分
- IE是否可以直接显示用gzip压缩的图片
- 10分,求数据库设计流程
- echo数组单元的值不全
- 怎样才能将输入在textarea中的文字,在导入数据库后再调用时仍保持相应的格式,如换 行、分段等?
- 【救急】Internet Explorer 已经已经遇到加载项故障并且需要关闭?????
- php调用存储过程后出错Commands out of sync; you can't run this command now
- win下php5.5.12装不上memcache扩展
类文件
mp3_cut_class.php
<?php
/*
作者:周春
电子邮件:xxfaxy#qq.com #换成@
微博:http://www.weibo.com/407497716
*/
class mp3_cut{
var $data_buffer=1048576;
var $error_message;
var $old_file;
var $new_file;
var $start_time;
var $file_size;
var $time_length;
var $byte_per_second;
var $input_data;
var $output_data;
var $type;
function mp3_cut($old_file,$time_length,$new_file,$start_time,$type){
$this->old_file=$old_file;
$this->new_file=$new_file;
$this->start_time=$start_time;
$this->time_length=$time_length;
$this->type=$type;
}
function cut(){
$this->set_input_file_size();
$this->byte_per_second();
$this->open_input_mp3();
$this->open_output_mp3();
$this->make_new_mp3($this->type);
$this->close_output_mp3();
$this->close_input_mp3();
}
function set_input_file_size(){
$this->file_size=@filesize($this->old_file);
}
function byte_per_second(){
$this->byte_per_second=(integer)($this->file_size/$this->time_length);
}
function make_new_mp3($type){
$start_position=$this->start_time*$this->byte_per_second;
if($type==1){
fseek($this->input_data,$start_position);
while(!@feof($this->input_data)){
@fwrite($this->output_data,@fread($this->input_data,$this->data_buffer));
}
}
else{
while(@ftell($this->input_data)<=((integer)$start_position)){
@fwrite($this->output_data,@fread($this->input_data,($this->byte_per_second/2)));
}
}
}
function open_input_mp3(){
if(file_exists($this->old_file)){
$this->input_data=fopen($this->old_file,"r");
$result=true;
}
else{
$this->error("打开文件错误");
$result=false;
}
return $result;
}
function close_input_mp3(){
if(@fclose($this->input_data)){$result=true;}
else{
$this->error("操作输入文件错误");
$result=false;
}
return $result;
}
function open_output_mp3(){
$this->output_data=@fopen($this->new_file,"w");
if($this->output_data){$result=true;}
else{
$this->error("创建文件错误");
$result=false;
}
return $result;
}
function close_output_mp3(){
if(@fclose($this->output_data)){$result=true;}
else{
$this->error("操作输出文件错误");
$result=false;
}
return $result;
}
function error($error_message){
$this->error_message.=$error_message."<br>";
}
}
?>
例子文件
index.php
<?php
require_once("mp3_cut_class.php");
$mp3_cut=new mp3_cut("input.mp3",265,"output.mp3",120,0);
//输入文件名,输入文件总时间,输出文件名,分割点时间,模式[0保存前段1保存后段]
$mp3_cut->cut();
echo $mp3_cut->error_message;
?>