1

我在我的应用程序中使用 Sonic-NDK 进行声音调制。因为它工作正常,但仅适用于音频文件。可以用来播放视频文件吗?这是库源代码的链接,我的代码虽然相同,但遵循..

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();
}}
4

1 回答 1

0

对于使用任何视频播放器播放视频,Sonic 库用于更改音频文件属性,如音高、频率、速度等。

于 2013-09-25T13:11:54.907 回答