public class main extends Activity {
/*
The function videoViewURL(url) works anywhere else
in my program but here!!
It needs to be called from one of these places.
I think it has to do with class hiearchy.
Also I believe passing the function setUrl(url) another parameter might work.
The other parameter being a Function
So what I'm asking is this. Does anyone know how to pass
setUrl(url, function videoViewURL(url)){
videoViewURL(this.url);
}
*/
public void videoViewURL(String url){
MediaController mc = new MediaController(this);
mc.setAnchorView(videoView);
mc.setMediaPlayer(videoView);
videoView.setMediaController(mc);
Uri video = Uri.parse(url);
videoView.setVisibility(VideoView.VISIBLE);
videoView.setVideoURI(video);
videoView.start();
// mc.show();
}
public class jsVideo{ // Option1
public void setUrl(String url){
//Toast.makeText(getBaseContext(), url, Toast.LENGTH_LONG).show(); This works and returning valid url!
videoViewURL(url); // This doesn't
}
}
}
class jsVideo{ // Option2
public void setUrl(String url){
Context mContext;
// I've even tryed main m;
jsVideo(Context c) {
mContext = c;
// m = main; but this still doesn't work
}
//Toast.makeText(mContext;, url, Toast.LENGTH_LONG).show(); This works and returning valid url!
videoViewURL(url); // This doesn't
}
我的VideoView可以解决问题,它不会让我从这两个地方调用它。如果我可以附加项目,我会把它剥离到尽可能紧凑。谢谢。
答案 0 :(得分:0)
这是在onCreate()
之前 final Handler myHandler = new Handler();
这就是示例中的位置。
public class jsVideo{ // <stupid Class Object Wrapper
public void setUrl(String url){
Toast.makeText(getBaseContext(), url, Toast.LENGTH_LONG).show();
final String msgURL = url;
myHandler.post(new Runnable(){
@Override
public void run(){
videoViewURL(msgURL);
}
});
}
}