Experiment 6 play audio and video in the app

Source: Internet
Author: User

Lab Report

Course Name

Mobile Internet development based on Android platform

Date of experiment

2015.4.16

Name of the experimental project

Experiment 6 play audio and video in the app

Location of the experiment

S30010

Type of experiment

-Verification Type √ design type-comprehensive type

Hours

2

The purpose and requirements of the experiment (the knowledge points which are involved in this experiment and are required to be mastered)

1. Implement audio and video processing in the application.

2. Realize playback audio, audio playback control;

3. Realize playback video, video playback control;

4. Use service services to play music from the project source file.

second, the experimental environment (the hardware equipment and related software used in this experiment)

(1) PC Machine

(2) Operating system: Windows XP

(3) Software: Eclipse, jdk1.6,android Sdk,adt

Third, the contents and steps of the experiment

1) New Project

2) Modify the layout file Main.xml

3) Perfect Activity class

Four, the experimental results (the experimental source program list and operating results or experimental conclusions, experimental design drawings)

Code:

protected void onCreate (Bundle savedinstancestate) {

TODO auto-generated Method stub

Super. OnCreate (savedinstancestate);

Setcontentview (r.layout. Mediapaly);

Btnstart= (ImageButton) Findviewbyid (r.id. Btnstart);

Btnpause= (ImageButton) Findviewbyid (r.id. Btnpause);

btnstop= (ImageButton) Findviewbyid (r.id. Btnstop);

Btnyuan= (Button) Findviewbyid (r.id. Yuan);

Netbtn= (Button) Findviewbyid (r.id. NET);

Benbtn= (Button) Findviewbyid (r.id. Bendi);

Tingbtn= (Button) Findviewbyid (r.id. Tingzhi);

Tuibtn= (Button) Findviewbyid (r.id. Tui);

tv= (TextView) Findviewbyid (r.id. TV);

Btnstart.setonclicklistener (new Onclicklistener () {

@Override

Public void OnClick (View arg0) {

TODO auto-generated Method stub

Player=mediaplayer. Create (Mediaplay. this, R.raw. nan);

Player.start ();

Tv.settext ("Playing music ....") ");

}

});

Btnstop.setonclicklistener (new Onclicklistener () {

@Override

Public void OnClick (View arg0) {

TODO auto-generated Method stub

if (Player.isplaying ()) {

Player.stop ();

Tv.settext ("Music stops playing! ");

}

}

});

Btnpause.setonclicklistener (new Onclicklistener () {

@Override

Public void OnClick (View arg0) {

TODO auto-generated Method stub

if (Player.isplaying ()) {

Player.pause ();

Tv.settext ("Music Paused! ");

}Else{

Player.start ();

}

}

});

Btnyuan.setonclicklistener (new Onclicklistener () {

@Override

Public void OnClick (View arg0) {

TODO auto-generated Method stub

Player=mediaplayer. Create (Mediaplay. this, R.raw. nan);

Player.start ();

}

});

file=New File (environment. getExternalStorageDirectory(). GetPath () + "/nan.mp3");

if (File.exists ()) {

Player=mediaplayer. Create (Mediaplay. this, Uri. Parse (File.getabsolutepath ()));

}Else {

Toast. Maketext (Mediaplay. This, "The file does not exist!" ", Toast. Length_long). Show ();

}

Benbtn.setonclicklistener (new Onclicklistener () {

@Override

Public void OnClick (View arg0) {

TODO auto-generated Method stub

Player.reset ();

Try {

Player.setdatasource (File.getabsolutepath ());

Player.prepare ();

Player.start ();

} catch (IllegalArgumentException e) {

TODO auto-generated Catch block

E.printstacktrace ();

} catch (SecurityException e) {

TODO auto-generated Catch block

E.printstacktrace ();

} catch (IllegalStateException e) {

TODO auto-generated Catch block

E.printstacktrace ();

} catch (IOException e) {

TODO auto-generated Catch block

E.printstacktrace ();

}

}

});

Tingbtn.setonclicklistener (new Onclicklistener () {

@Override

Public void OnClick (View arg0) {

TODO auto-generated Method stub

if (Player.isplaying ()) {

Player.pause ();

Tv.settext ("Music Paused! ");

}Else{

Player.start ();

}

}

});

Tuibtn.setonclicklistener (new Onclicklistener () {

@Override

Public void OnClick (View arg0) {

TODO auto-generated Method stub

if (Player.isplaying ()) {

Player.stop ();

Tv.settext ("Music stops playing! ");

}

}

});

}

Run:

Five, Experimental summary (analysis of the results of the experiment, experience and improvement of experimental ideas)

The content of the experiment is very interesting, according to the teacher's steps and methods can successfully complete the experiment, very meaningful, next time

Experimental reviews

Experimental results

Guide Teacher Signature: Date

Experiment 6 play audio and video in the app

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.