Toggle playback of short video (if The phone needs to press the button to toggle the Screen)
Source: Internet
Author: User
<span id="Label3"></p><p><p>Package com.example.meidiaplayar;</p></p><p><p></p></p><p><p>Import android.os.Bundle;<br>Import android.os.Environment;<br>Import android.app.Activity;<br>Import android.view.Menu;<br>Import android.widget.MediaController;<br>Import android.widget.VideoView;</p></p><p><p>public class Mainactivity extends Activity {</p></p><p><p>Private Videoview videoview;</p></p><p><p>@Override<br>protected void OnCreate (Bundle Savedinstancestate) {<br>Super.oncreate (savedinstancestate);<br>Setcontentview (r.layout.activity_main);<br><br>Videoview = (videoview) Findviewbyid (r.id.video);<br><br>String path=environment.getexternalstoragedirectory (). GetPath ();<br>Set the video path<br>Videoview.setvideopath ("/mnt/sdcard/xiaopohai.3gp");<br>Setting up the Controller<br>Mediacontroller controller=new Mediacontroller (mainactivity.this);<br>Videoview.setmediacontroller (controller);<br>Controller.setmediaplayer (videoview);<br>Videoview.start ();<br>Give the saved data to Videoview<br>If (savedinstancestate!=null) {<br>int time = Savedinstancestate.getint ("time");<br>Videoview.seekto (time);<br>}<br>}</p></p><p><p>When switching the screen, go to the following code;<br>@Override<br>protected void Onsaveinstancestate (Bundle Outstate) {<br>TODO auto-generated Method Stub<br><br>Outstate.putint ("time", videoview.getcurrentposition ());<br>Super.onsaveinstancestate (outstate);<br>}</p></p><p><p>}</p></p><p><p> Toggle playback of short video (provided The phone needs to press the button to toggle the Screen) </p> </p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service