The video recording function of mobile phone is realized

Source: Internet
Author: User

With the advent of the Mobile internet era, a new era has begun. The so-called mobile internet is the integration of mobile communications and the Internet, so that mobile devices (including mobile phones and netbooks) can access the Internet resources and applications anytime and anywhere. The internet era created an economic myth, and also created a lot of times heroes, they are admirable. Imagine a hundreds of millions of of mobile phone users and hundreds of millions of of netizens to build a common platform, so that it can be applied to business, business and rural areas, and what a earth-shattering Albert? The new era begins, would you like to lose on the starting line? The development of Android-related apps comes with it. Let's start by explaining the details of the video recording.

How to play one of the available media audio in your own application :

1.put the file in your project's Res/raw folder, in This folder,the Eclipse plugin will find it, at the same time, will be this resource with your R

associated with the class;

2.Create a MediaPlayer and use Mediaplayer.create to correlate with the resource, and then use the start () method in the instance .

For example: Mediaplayermp=mediaplayer.create (context,r.raw.sound_file_1);

Mp.start ();

If you want to stop playback, use the Stop () method. If you want to replay this media later , you must use the start () method again before using the

The Reset () method and the prepare () method manipulate the MediaPlayer object. (Create () call prepare () for the first time )

If you want to pause playback, you can use the pause () method. The Resume playback function can be implemented using the start () method where you paused .

Play a file

Here's how to play a file:

1, Create a MediaPlayer instance with new ;

2, call the Setdatasource () method, this method has a string parameter, this string type parameter contains you want to play the

the path to the file-the local file system or the URL;

3,after that, call the Prepare () method First, then the start () method.

For example:

MediaPlayer mp=new MediaPlayer ();

Mp.setdatasource (Path_to_file);

Mp.prepare ();

Mp.start ();

one thing to note: If you're passing a URL Way of the file, then this file must be downloadable, and is uninterrupted, simply

Said to be downloaded at the same time as the playback.

How to record media audio resources:

1, use new to create an instance Android.media.MediaRecorder;

2.Create a android.content.ContentValues instance and set some standard properties, like TITLE,TIMESTAMP, and most importantly Mime_type;

3.create a path to the file to be placed, which can be created by Android.content.ContentResolver in the content database to create a

and automatically signs a path to the file.

4.use the Mediarecorder.setaudiosource () method to set up audio resources; This will most likely be used to MediaRecorder.AudioSource.MIC;

5, use the Mediarecorder.setoutputformat () method to set the output file format;

6, using the Mediarecorder.setaudioencoder () method to set the audio encoding;

7, finally,the audio recorded byprepare () and start (), Stop () and release () are called at the end of the call.

Here is an example:

Recorder=new Mediarecorder ();

Contentvalues values=new contentvalues (3);

Values.put (Mediastore.mediacolumns.title,some_name_here);

Values.put (Mediastore.mediacolumns.timestamp,system.currenttimemillis ());

Values.put (Mediastore.mediacolumns.mime_type,recorder.getmimecontenttype ();

Contentresolver Contentresolver=newcontentresolver ();

Uribase=mediastore.audio.internal_content_uri;

Urinewuri=contentresolver.insert (base,values); inserts a column of data into a table at the given URL

function prototype:final Uri Insert (url,contentvalues values);

if (newuri==null) {

exception handling is required here, and we cannot create a new content entry here.

}

Stringpath=contentresolver.getdatafilepath (Newuri);

You can use setpreviewdisplay () to display a preview to fit the View

Recorder.setaudiosource (MediaRecorder.AudioSource.MIC);

Recorder.setoutputformat (MediaRecorder.OutputFormat.THREE_GPP);

Recorder.setaudioencoder (MediaRecorder.AudioEncoder.AMR_NB);

Recorder.setoutputfile (path);

Recorder.prepare ();

Recorder.start ();

To stop recording:

Recorder.stop ();

Recorder.release ();

In the process of recording audio resources, the use of the Contentvalues This class, below to explain this class.

Contentvalues This class is used to store a series of values that require contentresolver to process .

The contentvalues (int size) constructor creates an empty series value with the given initial value.

Contentvalues (contentvalues from) This constructor creates a value that is generated from the given contentvalues for replication.

This class has the following common methods :

void Clear () to remove all values

Boolean ContainsKey (String key) returns True if the object has a named value

int describecontents () describes value types

Object get (String key) Gets the value

void put (String Key,integer value) adds a value to the corresponding set

Video Recording is one of the Android video development, video surveillance, video traffic and other development are implemented on the Android platform, the future cross-platform Android Market is more colorful. Android phone when remote control with, mobile phone connection TV set-top box. These are not sci-fi characters in fiction, but facts. beginning with the year, the "Triple network integration" formally by the State Council into Twelve-Five plans and began to implement. The State Council has made it clear that the integration of the three networks as an important means to improve the level of information technology, and highlight the importance of the three-network integration in the national strategic level development, but also for the three network integration in the 35 period of the development of a clear direction and objectives. In the same governance platform, the realization of audio, video, data transmission and management, to provide a variety of broadband applications and traditional telecommunications services, is a true broadband narrowband integration, wired and wireless integration, active passive integration, transmission and integration of integrated service network. Let a fiber solve the dream of watching TV, making phone calls and surfing the internet into reality.


Video recording on mobile devices

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.