Play mp4 file from URL on android

帅比萌擦擦* 提交于 2019-12-12 04:09:26

问题


I've been researching for some time now, and all the questions I can find point to mp4 'hinting' but I have no control over the videos.

I was about to give up when i discovered that MX video player on the android market can somehow play these mp4 urls I have. So at the moment I use an intent to launch the urls in mx player but I'd much rather display the video within my app.

Any ideas how mx player does this would be great,

Thanks


回答1:


Refer this link i had pasted the whole code for playing the mp4 videos in your app by creating a videoview and you might minor error you can manually remove that error.




回答2:


Check this. It will help you.

String LINK = "http://www.boisestatefootball.com/sites/default/files/videos/original/01%20-%20coach%20pete%20bio_4.mp4";
setContentView(R.layout.video);
VideoView videoView =(VideoView)findViewById(R.id.webView);
MediaController mc = new MediaController(this);
mc.setAnchorView(videoView);
mc.setMediaPlayer(videoView);
Uri video = Uri.parse(LINK);
videoView.setMediaController(mc);
videoView.setVideoURI(video);
videoView.requestFocus();
videoView.start();



回答3:


You can do it using FullscreenVideoView class. Its a small library project. it's gradle is :

compile 'com.github.rtoshiro.fullscreenvideoview:fullscreenvideoview:1.1.0'

It's steps is here:

your VideoView xml is like this

<com.github.rtoshiro.view.video.FullscreenVideoLayout
        android:id="@+id/videoview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

In your activity , initialize it using this way:

    FullscreenVideoLayout videoLayout;
videoLayout = (FullscreenVideoLayout) findViewById(R.id.videoview);
        videoLayout.setActivity(this);

        Uri videoUri = Uri.parse("YOUR_VIDEO_URL");
        try {
            videoLayout.setVideoURI(videoUri);

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

That's it. Happy coding :)

If want to know more then visit here



来源:https://stackoverflow.com/questions/10870660/play-mp4-file-from-url-on-android

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