1

我想创建一个 android 应用程序,它可以将一些音频文件从 Eclipse 项目的原始文件夹复制到 sd 卡。文件已复制到 sd 卡,但无法播放媒体播放器,并显示下一条消息“播放器不支持此类音频文件”,似乎文件已损坏,但我不知道原因。这是我的代码:

Button copy = (Button) findViewById(R.id.button2);
    copy.setOnClickListener(new View.OnClickListener(){
        public void onClick(View view) {

            File sdCard, directory = null;
            String nombreMP3 = "audio.mp3";
            BufferedInputStream  entrada = null;
            BufferedOutputStream salida = null;
            int len=0;
            sdCard = Environment.getExternalStorageDirectory();
            directory = new File( sdCard.getAbsolutePath() + "/CarpetaAplicacion2");
            if (!directory.exists()){
                directory.mkdir();
            }
            File f = new File(directory, nombreMP3);
            try {                   
                entrada = new BufferedInputStream(getResources().openRawResource(R.raw.dignidad));
                salida = new BufferedOutputStream((new FileOutputStream(f)),4096);
                byte[] buff = new byte[4096];
            while ((len=entrada.read()) > 0){   
                synchronized (buff){
                    salida.write(buff,0,len);
                    salida.flush();}
            }

            } catch (IOException ex) { 
                if( entrada != null){
                    try {
                        entrada.close();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }}
                if (salida != null) {
              try {
                salida.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }}
            }
            finally{
                if( entrada != null){
                    try {
                        entrada.close();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }}
                if (salida != null) {
              try {
                salida.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
4

0 回答 0