How to play audio only from video file on Android?

僤鯓⒐⒋嵵緔 提交于 2019-12-05 06:43:44

问题


I have mp4 and wmv movie files and need to play only sound not video screen. How to do it?? Could I get sound track from movie file??

I know if I hide the SurfaceView from screen, I can only hear sound.. but I have tried a lot but.. it is impossible.

If you have any solution to extract sound track from movie file, please let me know..

Thanks in advance.


回答1:


If you are using the mediaplayer API in your app then don't call the API public void setDisplay (SurfaceHolder sh). This will ensure that only the audio is played out even if the video content is present..

More info in android doc here




回答2:


Use following code, Optimize following code as per your requirement. It play video from youtube.

try {
            final MediaPlayer m = new MediaPlayer();
            Thread t = new Thread(new Runnable() {

                public void run() {
                    try {
                        m.setDataSource("rtsp://v8.cache3.c.youtube.com/CjgLENy73wIaLwlQP1m32SiSYxMYJCAkFEIJbXYtZ29vZ2xlSARSB3JlbGF0ZWRggqG7w9aS2-1MDA==/0/0/0/video.3gp");
                        m.prepare();
                        m.start();  
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }
            });
            t.start();

        } catch (Exception e) {
            e.printStackTrace();
        }


来源:https://stackoverflow.com/questions/6056034/how-to-play-audio-only-from-video-file-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!