How to play a streaming video from URL in android?

…衆ロ難τιáo~ 提交于 2019-12-10 22:37:49

问题


I want to play a streaming video in android from a website.

For example, I want to play the streaming video from this url: http://florotv.com/canal2.html

Using URL Helper, I have been able to capture the rtmp URL that it's

rtmp://198.144.153.139:443/kuyo<playpath>ver44?id=acf6f5271f8ce567ed6c8737ce85a044&pid=32342e3136362e37332e323139 <swfUrl>http://yukons.net/yplay2.swf <pageUrl>http://yukons.net/embed/37363635373233343334/eeff74c57593ca38defc902fa6d88005/600/400

Now that I have this URL, I wanna know if it's possible to play the video in android.

I have tried this but it doesn't work because I don't know how to set the swfUrl, pageUrl.....

private static final String MOVIE_URL="rtmp://198.144.153.139:443/kuyo";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
Uri data = Uri.parse(MOVIE_URL);
intent.setData(data);
startActivity(intent);

Thanks in advance....


回答1:


I don't think it's enough to just create an intent, you also have to create a context for the video to be played : Like a VideoView object.

The link below has a suggestion for this pattern : http://androidcodeexamples.blogspot.sg/2011/08/how-to-play-mp4-video-in-android-using.html

Essentially a MediaController object is created with the VideoView object. Then the VideoView is used to start the operation once the URI is set.

Edit : Probably the main problem though is that your URL contains POST parameters and isn't exactly a unique identifier of a resource (in this case a video file).

The 'swfUrl' and 'pageUrl' parameters are most likely unique to the server that's providing you the page.




回答2:


You can use Vitamio library for android, where you can set the swfUrl and pageUrl.

Here is a tutorial for it.




回答3:


Add below code into your Activity.java file.

protected void onCreate(Bundle savedInstanceState)
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.videoPlayer);
try {        
    String link="http://videocloud/video.mp4";
    VideoView videoView = (VideoView) findViewById(R.id.myVideoView);
    final ProgressBar pbLoading = (ProgressBar) findViewById(R.id.pbVideoLoading);
    pbLoading.setVisibility(View.VISIBLE);
    MediaController mediaController = new MediaController(this);
    mediaController.setAnchorView(videoView);
    Uri video = Uri.parse(link);
    videoView.setMediaController(mediaController);
    videoView.setVideoURI(video);
    videoView.start();
    videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                        @Override
                        public void onPrepared(MediaPlayer mp) {
                            pbLoading.setVisibility(View.GONE);
                        }
    });
} catch (Exception e) {
    // TODO: handle exception
    Toast.makeText(this, "Error connecting", Toast.LENGTH_SHORT).show();
}

}

If you don't need MediaController set it to null videoView.setMediaController(null)



来源:https://stackoverflow.com/questions/21620550/how-to-play-a-streaming-video-from-url-in-android

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