如何使用设备中的默认播放器在Android中播放3gp音频文件?

如何使用设备中的默认播放器在Android中播放3gp音频文件?,第1张

概述我需要播放存储在我的SD卡位置的3gp音频文件,以便在My HTC设备中使用我的默认媒体播放器播放它. 请帮忙 代码: public class AudioRecorder extends Activity { private static final String CAMERA_STATUS = "camera_upload"; private static fina @H_419_1@ 我需要播放存储在我的SD卡位置的3gp音频文件,以便在My HTC设备中使用我的默认媒体播放器播放它.

请帮忙

代码:

public class AudioRecorder extends Activity {     private static final String CAMERA_STATUS = "camera_upload";        private static final String galLERY_STATUS = "gallery_upload";        MediaRecorder recorder = new MediaRecorder();        static String path = "audio-androID.3gp";        button startRecording;        button stopRecording;        button save;        button palyAudio;        private Context context;     private String sanitizePath(String path) {        if (!path.startsWith("/")) {            path = "/" + path;        }        if (!path.contains(".")) {            path += ".3gp";        }        return Environment.getExternalStorageDirectory().getabsolutePath()            + path;        }     @OverrIDe        protected voID onCreate(Bundle savedInstanceState) {        // Todo auto-generated method stub        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.audio_recording);        context = this;        /**         * Creates a new audio recording at the given path (relative to root of         * SD card).         */        this.path = sanitizePath(path);        startRecording = (button) findVIEwByID(R.ID.startRecording);        stopRecording = (button) findVIEwByID(R.ID.stopRecording);        save = (button) findVIEwByID(R.ID.resetRecording);        palyAudio = (button) findVIEwByID(R.ID.playRecorded);startRecording.setonClickListener(new OnClickListener() {            @OverrIDe            public voID onClick(VIEw arg0) {            try {                stopRecording.setVisibility(VIEw.VISIBLE);                startRecording.setVisibility(VIEw.GONE);                start();            } catch (IOException e) {                e.printstacktrace();            }            }        });        stopRecording.setonClickListener(new OnClickListener() {            @OverrIDe            public voID onClick(VIEw arg0) {            stopRecording.setVisibility(VIEw.GONE);            startRecording.setVisibility(VIEw.VISIBLE);            try {                            stop();            } catch (IOException e) {                // Todo auto-generated catch block                e.printstacktrace();            }            }        });        palyAudio.setonClickListener(new OnClickListener() {            @OverrIDe            public voID onClick(VIEw arg0) {             playAudio();             //startMediaPlayer();            }        });        }        /**         *          * play the recorded audio         *          */        public voID playAudio() {        try {            Intent intent = new Intent(androID.content.Intent.ACTION_VIEW);            Uri data = Uri.parse(path);           // Intent intent = new Intent(Intent.ACTION_VIEW,data);              intent.setDataAndType(data,"audio/mp3");            startActivity(intent);        } catch (ActivityNotFoundException e) {            e.printstacktrace();        } catch (Exception e) {            // Todo: handle exception        }        }      /**         * Starts a new recording.         */        public voID start() throws IOException {        recorder = new MediaRecorder();        String state = androID.os.Environment.getExternalStorageState();        if (!state.equals(androID.os.Environment.MEDIA_MOUNTED)) {            throw new IOException("SD Card is not mounted.  It is " + state                + ".");        }        // make sure the directory we plan to store the recording in exists        file directory = new file(path).getParentfile();        System.out.println("start() directory >  " + directory);        if (!directory.exists() && !directory.mkdirs()) {            throw new IOException("Path to file Could not be created.");        }        recorder.setAudioSource(MediaRecorder.AudioSource.MIC);                 recorder.setoutputFormat(MediaRecorder.OutputFormat.THREE_GPP);         recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);    recorder.setoutputfile(path);         recorder.prepare();                       recorder.start();         }        /**         * Stops a recording that has been prevIoUsly started.         */        public voID stop() throws IOException {        recorder.stop(); // Stops recording.        recorder.release(); // Now the object cannot be reused        }    }
解决方法
public voID onCreate(Bundle icicle) {        super.onCreate(icicle);        setContentVIEw(t);        path = "/sdcard/sample.mp3";                    mMediaPlayer = new MediaPlayer();                    mMediaPlayer.setDataSource(path);                    mMediaPlayer.prepare();                    mMediaPlayer.start();    }
总结

以上是内存溢出为你收集整理的如何使用设备中的默认播放器在Android中播放3gp音频文件?全部内容,希望文章能够帮你解决如何使用设备中的默认播放器在Android中播放3gp音频文件?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1123040.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存