我在我的应用程序中使用Sonic-NDK进行声音调制。因为它工作正常,但只适用于音频文件。它可以用来播放视频文件吗? 这是库的源代码的link,我的代码虽然相同但是跟随..
public class SonicTest extends Activity
{
VideoView videoView;
String uri;
FileInputStream soundFile=null;
File file;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void play(View view)
{
new Thread(new Runnable()
{
public void run()
{
float speed= (float) 1.0;
float pitch= (float) 1.5;
float rate= (float) 1.0;
uri= Environment.getExternalStorageDirectory().toString();
uri=uri+"/talking.bin";
Log.i("testing","check if uri is correct "+uri);
AndroidAudioDevice device = new AndroidAudioDevice(22050, 1);
Sonic sonic = new Sonic(22050, 1);
byte samples[] = new byte[4096];
byte modifiedSamples[] = new byte[2048];
//soundFile = getContentResolver().openInputStream(Uri.parse(uri));
/*soundFile=getResources().openRawResource(R.raw.video3);
Log.i("testing","check if SoundFile is correct "+soundFile);
*/
file= new File(uri);
try {
soundFile= new FileInputStream(file);
Log.i("testing","check if SOUNDFILE is correct "+soundFile);
} catch (FileNotFoundException e1) {
Log.i("testing","File Not Supported");
e1.printStackTrace();
}
int bytesRead;
if(soundFile != null) {
sonic.setSpeed(speed);
sonic.setPitch(pitch);
sonic.setRate(rate);
do {
try {
bytesRead = soundFile.read(samples, 0, samples.length);
} catch (IOException e) {
e.printStackTrace();
return;
}
if(bytesRead > 0) {
sonic.putBytes(samples, bytesRead);
} else {
sonic.flush();
}
int available = sonic.availableBytes();
if(available > 0) {
if(modifiedSamples.length < available) {
modifiedSamples = new byte[available*2];
}
sonic.receiveBytes(modifiedSamples, available);
device.writeSamples(modifiedSamples, available);
}
} while(bytesRead > 0);
device.flush();
}
}
} ).start();
}}
答案 0 :(得分:0)
使用任何视频播放器播放视频时,Sonic库用于更改音高,频率,速度等音频文件属性。