android開發過程中遇到的小問題

來源:互聯網
上載者:User

1、在編寫xml布局的時候,總是提示[Accessibility] Missing contentDescription attribute on image的警告資訊

解決方案:

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

修改為:

<ImageView    android:layout_width="210dp"    android:layout_height="32dp"    android:layout_centerHorizontal="true"    android:contentDescription="組件的描述內容"    />

 2、在android編寫布局的時候,我們有時候需要將一個類封裝成一個組件來使用,那麼體現在介面上的方法有兩種,1.xml布局,2.代碼編寫

第一種:xml布局

如果是xml布局需要注意兩點

a.類的構造方法中必須添加

public 類名(Context context, AttributeSet attribute) {  }

b.在xml中的形式如下:

<包名.類名     屬性  />

第二種代碼布局,只需要構造

public 類名(Context context) {}

3、在播放音訊時候使用AudioTrack來實現,但是多次實現audioTrack.play,audioTrack.stop會出現如下現象:

obtainBuffer() track 0x17c418 disabled, restarting

原因為:

在迴圈使用AudioTrack.write(byte[] audioData, int offsetInBytes, int sizeInBytes)寫入音頻資料時,由於網路原因和處理資料代碼邏輯亂的原因,音頻資料沒及時發送過來

解決方案:

這個方法可能只限於我現在產生這種現象的解決方案:

描述:通過socket來接收aac資料,我取一幀來然後通過faad來解碼成pcm碼流,然後放在audioTrack裡面播放,但是我是先初始化audioTrack.play,然後接收aac資料,調用faad解碼成pcm資料,最後把pcm資料寫到audioTrack裡面播放聲音。

解決方案:

造成這種現象的原因在上面已經寫出,由於資料沒有及時的寫入造成的,所以我這邊只初始化audioTrack執行個體,但不馬上進行audioTrack.play(),只有第一次來資料的時候才進行audioTrack.play,這樣就解決了我現在的問題。

/* * 播放音頻 */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);}}

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.