English 中文(简体)
只有在拍摄录像时才能显示黑色屏幕声的roid模拟器
原标题:android simulator showing black screen sound only when playing video

只有在拍摄录像时才能显示黑色屏幕的roid模拟器。 我的法典如下。

我在标识表中发现的错误是:

10-30 06:49:35.663: W/GraphicBufferAllocator(33): alloc(160, 128, 842094169, 00002930, ...) failed -22 (Invalid argument)
10-30 06:49:35.663: E/SurfaceFlinger(33): GraphicBufferAlloc::createGraphicBuffer(w=160, h=128) failed (Invalid argument), handle=0x0
10-30 06:49:35.663: E/SurfaceTexture(33): [SurfaceView] dequeueBuffer: SurfaceComposer::createGraphicBuffer failed
10-30 06:49:35.673: W/SoftwareRenderer(35): Surface::dequeueBuffer returned error -22

录像高度和宽度

10-30 06:49:35.223: D/Video Height:(595): 128
10-30 06:49:35.223: D/Video Width:(595): 160

我想的是,甲状腺可能 t着这种大小的录像,但似乎很.。 我曾尝试过几部录像,并且可以拍摄其中的任何录像(第4条或第3条)。 我只听到了声音。 录像是黑色的。 我可以在VLC中玩.,因此录像文件被罚款。 就在 and模拟器中,我可以发挥这种作用。

I m 用Ath4.0作为我的AVD。 Ie the simulator on PC.


package com.jevan.mediaplayer;

import java.io.IOException;
import android.app.Activity;
import android.content.res.AssetFileDescriptor;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.media.MediaPlayer.OnVideoSizeChangedListener;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MediaPlayerActivity extends Activity 
    implements SurfaceHolder.Callback, OnPreparedListener,
    OnVideoSizeChangedListener {
/** Called when the activity is first created. */
private int mVideoWidth=0;
private int mVideoHeight=0;
private MediaPlayer mp = null;
private SurfaceHolder holder = null;
private SurfaceView sv = null;
private boolean mIsVideoReadyToBePlayed = false;
private boolean mIsVideoSizeKnown = false;
private Button myButton = null;

    public void surfaceCreated(SurfaceHolder holder) {
        /*MediaPlayer mediaPlayer = MediaPlayer.create(context, uri);
        mediaPlayer.start(); // no need to call prepare(); create() does that for you
        */
        Log.d("surfaceCreated()", "surfaceCreated called");
        mp = new MediaPlayer();

        AssetFileDescriptor afd = null;
        try {
            afd = getAssets().openFd("747.3gp");
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        try {
            mp.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength());
        } catch (IllegalArgumentException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IllegalStateException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        try {
            afd.close();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        /*
        try {
            mp.setDataSource("http://www.mp4point.com/downloads/d7c320246079.mp4");
        } catch (IllegalArgumentException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (SecurityException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IllegalStateException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        */

        mp.setDisplay(holder);
        try {
            mp.prepare();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        mp.setOnPreparedListener(this);
        mp.setOnVideoSizeChangedListener(this);

        mp.setAudioStreamType(AudioManager.STREAM_MUSIC);

        /*setVolumeControlStream(AudioManager.STREAM_MUSIC);*/

        mp.setScreenOnWhilePlaying(true); 

        Log.d("Video Height:", Integer.toString(mp.getVideoHeight()));
        Log.d("Video Width:", Integer.toString(mp.getVideoWidth()));

        mp.setLooping(false);

        //mp.start(); 
        // i.e. react on the end of the music-file: 
        /*
        mp.setOnCompletionListener(new 
                OnCompletionListener(){ 
            public void onCompletion(MediaPlayer arg0) { 
                // File has ended 
            } 
        });
        */

        Log.d("surfaceCreated()", "surfaceCreated finishing");
    }

    public void surfaceChanged(SurfaceHolder holder,
            int format, int width, int height) {
        // TODO Auto-generated method stub

    }

    public void surfaceDestroyed(SurfaceHolder holder) {
        // TODO Auto-generated method stub

    }

    public void onPrepared(MediaPlayer mediaplayer) {
        Log.d("onPrepared", "onPrepared called");
        mIsVideoReadyToBePlayed = true;
        if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
            startVideoPlayback(mediaplayer);
        }
        Log.d("onPrepared", "onPrepared finishing");
    }

    private void startVideoPlayback(MediaPlayer mediaplayer) {
        if (!(mediaplayer.isPlaying())) {
            holder.setFixedSize(mVideoWidth, mVideoHeight);
            mediaplayer.start();
        }
    }

    public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
        Log.d("onVideoSizeChanged",
                "onVideoSizeChanged called (Width "+Integer.toString(width)+" Height "+Integer.toString(height)+")");
        if (width == 0 || height == 0) {
            Log.e("Log", "invalid video width(" + width + ") or height(" + height + ")");
            return;
        }
        mIsVideoSizeKnown = true;
        mVideoWidth = width;
        mVideoHeight = height;
        if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
            startVideoPlayback(mp);
        }
    }

    private void releaseMediaPlayer() {
        Log.d("releaseMediaPlayer", "releaseMediaPlayer called");
        if (mp != null) {
            mp.release();
            mp = null;
            Log.d("releaseMediaPlayer", "mp release has been called and mp made null");
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        releaseMediaPlayer();
        doCleanUp();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        releaseMediaPlayer();
        doCleanUp();
    }

    private void doCleanUp() {
        mVideoWidth = 0;
        mVideoHeight = 0;
        mIsVideoReadyToBePlayed = false;
        mIsVideoSizeKnown = false;
    }

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Log.d("onCreate", "onCreate called");
    sv = (SurfaceView) findViewById(R.id.surface_view); 
    holder = sv.getHolder();
    holder.addCallback(this);
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    myButton = (Button)this.findViewById(R.id.button); 
    myButton.setOnClickListener(new OnClickListener(){ 
           public void onClick(View arg0) {
               if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
                   startVideoPlayback(mp);
               }
           }
    });
    Log.d("onCreate", "onCreate finishing");
} 
}

My main.xml looks like this:

 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent" android:layout_height="fill_parent">

<Button android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:id="@+id/button"
    android:text="Start Video" android:layout_alignParentBottom="true" />

<SurfaceView android:id="@+id/surface_view"
      android:layout_height="fill_parent"
      android:layout_width="fill_parent"
      android:layout_above="@+id/button"></SurfaceView>

 </RelativeLayout>
问题回答

在固定装置方面,我也存在同样的问题,最糟糕的是,这种装置似乎每次都发生,因此很难解冻。 d 我建议使用视频电文,但这样会自动地大小,并公平地一致运作,例如:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:layout_gravity="fill|bottom" android:gravity="fill|bottom">
    <LinearLayout android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true" android:layout_alignParentRight="true"
        android:layout_alignParentLeft="true" android:layout_width="match_parent"
        android:layout_height="match_parent" android:gravity="center">
        <VideoView android:id="@+id/videoView"
            android:layout_centerInParent="true" android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
    <Button android:id="@+id/activate_button" style="@style/buttonStyle"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_gravity="bottom|center_horizontal"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true" android:layout_alignParentLeft="true"
        android:onClick="activateClick" android:text="@string/activateButtonLabel" />
</RelativeLayout>

用于:

public class ExternalMediaPreview extends Activity implements OnPreparedListener
    {

        private VideoView           mVideoView;
        protected int               resid;
        protected String            mediaPackage;
        protected ActivityInfo      mActivityInfo;

        public ExternalMediaPreview()
            {
                super();
            }

        @Override
        public void onCreate( Bundle icicle )
            {
                super.onCreate( icicle );
                requestWindowFeature( Window.FEATURE_NO_TITLE );
                setContentView( R.layout.video_preview );
                mVideoView = ( VideoView ) findViewById( R.id.videoView );
                mVideoView.setOnPreparedListener( this );
                try
                    {
                        Uri uri = Uri.parse( "android.resource://" + getPackageName() + "/" + R.raw.test_video );
                        mVideoView.setVideoURI( uri );
                        Log.i( TAG, "Uri loaded: " + uri.toString() );
                    }
                catch( Exception e )
                    {
                        e.printStackTrace();
                    }
            }
        @Override
        public void onPrepared( MediaPlayer mp )
            {
                Log.i( TAG, "videoView prepared, setting loop to true" );
                mp.setLooping( true );
                mVideoView.start();
            }
}




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签