Code Analysis of the Android multimedia playback function

Source: Internet
Author: User
Tags stub


Android Multimedia Playback code:

The code is as follows Copy Code


Import android.app.Activity;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.Button;
Import Android.widget.VideoView;
public class Videoplayer extends activity {
/** called the activity is a.
*/
@Override
public void OnCreate (Bundle icicle) {
Super.oncreate (Icicle);
Setcontentview (R.layout.main);
Final Videoview w = (videoview) Findviewbyid (R.id.vdoplayer);
Button Cmdload = (button) This.findviewbyid (r.id.cmd_load); Cmdload.setonclicklistener (New Onclicklistener () {
public void OnClick (View arg0) {
TODO auto-generated Method Stub
W.setvideopath ("/sdcard/android/kongfu.mp4");
}
}
);
Button Cmdplay = (button) This.findviewbyid (R.id.cmd_play);
Cmdplay.setonclicklistener (New Onclicklistener () {
public void OnClick (View arg0) {
TODO auto-generated Method Stub
W.start ();
}
}
);
Button Cmdpause = (button) This.findviewbyid (R.id.cmd_pause); Cmdpause.setonclicklistener (New Onclicklistener () {
public void OnClick (View arg0) {
TODO auto-generated Method Stub
W.pause ();
}
}
);
}

Android Multimedia playback Implementation code:
XML file:

  code is as follows copy code


<? XML version= "1.0" encoding= "Utf-8"?>
< linearlayout xmlns:android= "http://schemas.android.com/apk/res/" Android "android:orientation=" vertical "
android:layout_width=" fill_parent "
android:layout_height=" Fill_ Parent "
< Button android:id=" @+id/cmd_load "
android:layout_width=" fill_parent "
Android:layout_ height= "Wrap_content"
android:text= "Load"/>
< button android:id= "@+id/cmd_play"
Android:layout_ Width= "Fill_parent"
android:layout_height= "wrap_content"
android:text= "Play"/>
< Button android: Id= "@+id/cmd_pause"
android:layout_width= "fill_parent"
android:layout_height= "Wrap_content"
Android: text= "Pause"/>
< Videoview android:id= "@+id/vdoplayer"
android:layout_width= "Fill_parent"
Android : layout_height= "300px"/>
</linearlayout>

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.