Android錄製視頻報錯setVideoSize called in a invalid state 1

來源:互聯網
上載者:User

標籤:使用   exce   put   size   als   out   cap   代碼   this   

錄製視頻時想擷取手機支援的錄製視頻的解析度,使用代碼如下:

List<Camera.Size> videoSize = camera.getParameters().getSupportedVideoSizes();Iterator<Camera.Size> itos = videoSize.iterator();        while (itos.hasNext()) {            Camera.Size curSize = itos.next();            int curSupporSize = curSize.width * curSize.height;            int fixPictrueSize = setFixPictureWidth * setFixPictureHeight;            if (curSupporSize > fixPictrueSize) {                setFixPictureWidth = curSize.width;                setFixPictureHeight = curSize.height;            }        }mediaRecorder.setVideoSize(setFixPictureWidth,        setFixPictureHeight);

出現了兩次錯誤,一次是錄製視頻時調用camera.getParameters()時報parameters is empty,這是由於在camera.unlock()之後調用了該函數,將其在unlock之前擷取就ok了。
還有一個錯誤就是setVideoSize called in a invalid state 1,進入setVideoSize函數中可以發現拋出異常的條件說明

 /**     * Sets the width and height of the video to be captured.  Must be called     * after setVideoSource(). Call this after setOutFormat() but before     * prepare().     *     * @param width the width of the video to be captured     * @param height the height of the video to be captured     * @throws IllegalStateException if it is called after     * prepare() or before setOutputFormat()     */    public native void setVideoSize(int width, int height) throws IllegalStateException;

IllegalStateException if it is called after prepare() or before setOutputFormat()表示如果setVideoSize在prepare() 之後或者setOutputFormat()之前調用的話就會出現該異常,即是說要求setVideoSize函數在prepare()之前以及setOutputFormat()之後調用。
查了下代碼,發現我調用setVideoSize竟然是在setOutputFormat()之前,改到setOutputFormat()之後就ok了。

Android錄製視頻報錯setVideoSize called in a invalid state 1

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.