如何从android中的url播放字幕

时间:2013-10-26 16:26:24

标签: android url video android-videoview

如何使用从URL播放视频的URL启用服务器中联机的字幕?  我在视频中使用此代码:

公共类VideoViewActivity扩展了Activity {

// Declare variables
ProgressDialog pDialog;
VideoView videoview;

// Insert your Video URL
String VideoURL = "http://**************/mp4/Despicable.Me.2.2013.mp4";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Get the layout from video_main.xml
    setContentView(R.layout.videoview_main);
    // Find your VideoView in your video_main.xml layout
    videoview = (VideoView) findViewById(R.id.VideoView);
    // Execute StreamVideo AsyncTask

    // Create a progressbar
    pDialog = new ProgressDialog(VideoViewActivity.this);
    // Set progressbar title
    pDialog.setTitle("Android Video Streaming Tutorial");
    // Set progressbar message
    pDialog.setMessage("Buffering...");
    pDialog.setIndeterminate(false);
    pDialog.setCancelable(false);
    // Show progressbar
    pDialog.show();

    try {
        // Start the MediaController
        MediaController mediacontroller = new MediaController(
                VideoViewActivity.this);
        mediacontroller.setAnchorView(videoview);
        // Get the URL from String VideoURL
        Uri video = Uri.parse(VideoURL);
        videoview.setMediaController(mediacontroller);
        videoview.setVideoURI(video);

    } catch (Exception e) {
        Log.e("Error", e.getMessage());
        e.printStackTrace();
    }

    videoview.requestFocus();
    videoview.setOnPreparedListener(new OnPreparedListener() {
        // Close the progress bar and play the video
        public void onPrepared(MediaPlayer mp) {
            pDialog.dismiss();
            videoview.start();
        }
    });

}

}

.srt文件位于服务器的同一目录中

0 个答案:

没有答案