Wednesday, 15 January 2014

android - Why is VideoView not playing Video? -



android - Why is VideoView not playing Video? -

i trying play video starting when activity starts.

however,i getting black screen when activity starts.

i not understand why occurring.

is not proper way configure , play video?

hellomoonfragment:

public class hellomoonfragment extends fragment { private audioplayer mplayer = new audioplayer(); private button mplaybutton; private button mstopbutton; private button mpausebutton; private button mresumebutton; private button mstartvideo; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); } @override public view oncreateview(layoutinflater inflater,viewgroup parent,bundle savedinstancestate){ view v = inflater.inflate(r.layout.fragment_hello_moon,parent,false); mplaybutton = (button)v.findviewbyid(r.id.hellomoon_playbutton); mplaybutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { mplayer.play(getactivity()); } }); mstopbutton = (button)v.findviewbyid(r.id.hellomoon_stopbutton); mstopbutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { mplayer.stop(); } }); mresumebutton = (button)v.findviewbyid(r.id.hellomoon_startbutton); mresumebutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { mplayer.resume(); } }); mpausebutton = (button)v.findviewbyid(r.id.hellomoon_pausebutton); mpausebutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { mplayer.pause(); } }); mstartvideo = (button)v.findviewbyid(r.id.hellomoon_startvideo); mstartvideo.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent = new intent(getactivity(),videoactivity.class); startactivity(i); } }); homecoming v; } @override public void ondestroy(){ super.ondestroy(); mplayer.stop(); } }

videoactivity:

public class videoactivity extends activity { private string mvideopath = "android.resource://" + "com.tubbs.android.hellomoon" + "/" + "r.raw/apollo_17_stroll"; private uri mvideo; @override public void oncreate(bundle savedinstancestate){ super.oncreate(savedinstancestate); setcontentview(r.layout.activity_video); mvideo = uri.parse(mvideopath); videoview videoview = (videoview)findviewbyid(r.id.hellomoon_startvideo); mediacontroller mc = new mediacontroller(videoactivity.this); mc.setanchorview(videoview); videoview.setmediacontroller(mc); videoview.start(); } }

activity_video.xml file:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <videoview android:id="@+id/hellomoon_startvideo" android:layout_width="match_parent" android:layout_height="match_parent"/> </linearlayout>

android mobile videoview

No comments:

Post a Comment