0

我对 java 或 android 开发不熟悉(昨天才开始阅读)。我想用某个 url 调用 videoview 并将一些标题传递给它。我在网上搜索并找到了这个方法:

 package com.example.teste;

 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.Map;

 import android.app.Activity;
 import android.content.Context;
 import android.net.Uri;
 import android.os.Bundle;
 import android.widget.MediaController;
 import android.widget.VideoView;

 public class MainActivity extends Activity {


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Uri uri = Uri.parse("http://s2.ratotv.com/magic/4866/1.mp4");
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Host", "ratotv.com");
        headers.put("Referer", "http://www.ratotv.net/movies/1038-kick-ass-2-agora-a-doer.html");

        VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
        // Use java reflection call the hide API:
        Method method;
     try {
         method = myVideoView.getClass().getMethod("setDataSource", new Class[] { Context.class, Uri.class, Map.class });
         method.invoke(myVideoView, new Object[] {this, uri, headers});
         myVideoView.start();
} catch (IllegalAccessException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IllegalArgumentException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (InvocationTargetException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (NoSuchMethodException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
 }
}

但是,视频播放不会开始。

任何帮助都会非常感激。

4

0 回答 0