Minor issues encountered during Android Development

Source: Internet
Author: User

1. When writing an XML layout, the [accessibility] missing contentdescription attribute on image warning is always displayed.

Solution:

<ImageView    android:layout_width="210dp"    android:layout_height="32dp"    android:layout_centerHorizontal="true"    />

To:

<Imageview Android: layout_width = "210dp" Android: layout_height = "32dp" Android: layout_centerhorizontal = "true" Android: contentdescription = "component description"/>

2. When writing a layout in Android, we sometimes need to encapsulate a class into a component for use. There are two methods embodied in the interface: 1. XML layout, 2. code Writing

First: XML Layout

Pay attention to two points for XML layout.

A. The class constructor must be added.

Public Class Name (context, attributeset attribute ){}

B. the XML format is as follows:

<Package name. Class Name attribute/>

The second code layout, which only needs to be constructed

Public Class Name (context ){}

3. Use audiotrack to play audio. However, multiple audiotrack. Play and audiotrack. Stop operations may occur as follows:

obtainBuffer() track 0x17c418 disabled, restarting

The reason is:

Use audiotrack in a loop. write (byte [] audiodata, int offsetinbytes, int sizeinbytes) when writing audio data, the audio data is not sent in time due to network reasons and Data Processing code logic disorder.

Solution:

This method may be limited to the solutions that currently generate this phenomenon:

Description: uses a socket to receive AAC data. I take a frame and use faad to decode it into a PCM code stream and play it in audiotrack. However, I initialize audiotrack first. play, then receive AAC data, call faad to decode the PCM data, and write the PCM Data to audiotrack to play the sound.

Solution:

The reason for this problem has been written above. Because the data is not written in time, I only initialize the audiotrack instance, but do not perform audiotrack immediately. play (), which is used for audiotrack only when data is sent for the first time. play, which solves my current problem.

/** Play audio */Public void playvideo (byte [] data) {If (appinfortosystem. islistening & aaudio! = NULL & aaudio. getplaystate () = audiotrack. playstate_stopped) {aaudio. play (); aaudio. write (data, 0, 8192);} else if (appinfortosystem. islistening & aaudio! = NULL & aaudio. getplaystate () = audiotrack. playstate_playing) {aaudio. Write (data, 0, 8192 );}}

 

 

 

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.