【问题标题】:How to stream a video to play from a particular time in android?如何在android中流式传输视频以从特定时间播放?
【发布时间】:2011-12-15 07:42:30
【问题描述】:

谁能指导我如何播放特定时间的视频? 我有一个视频网址,我需要从我使用 seekTo() 的特定时间播放视频,但它不起作用。所以我认为首先我们需要将视频流式传输到文件然后我们需要播放......但我不知道如何从 url 流式传输视频。

谁能提供示例代码。

谢谢。

【问题讨论】:

    标签: android video-streaming


    【解决方案1】:

    你好,试试下面的方法对你有帮助

        <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
         <VideoView android:id="@+id/playvideo" 
            android:layout_height="fill_parent" 
            android:layout_width="fill_parent"
            android:keepScreenOn="true" 
            android:layout_centerInParent="true"></VideoView> 
    
    
    
    </RelativeLayout>
    

    安卓:

    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.videolayout);
            this.videoView=(VideoView)findViewById(R.id.playvideo);
    
    
             play();
    
        }
         private void play(){
                MediaController mediaController = new MediaController(this);
                mediaController.setAnchorView(this.videoView);  
    
             Uri video=Uri.parse("http://your.mp4/35.mp4");
                Log.e("Uri video",video.toString());
                videoView.setMediaController(mediaController);
                videoView.setVideoURI(video);     
                videoView.seekTo(60000*10);//10 mins...
                videoView.start();
                videoView.setOnCompletionListener(new OnCompletionListener(){
    
                    public void onCompletion(MediaPlayer arg0) {
                        // TODO Auto-generated method stub
    
                    }
    
                });
         }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-23
      • 2022-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多