English 中文(简体)
海底媒体参与者显示视听,但没有录像
原标题:android media player shows audio but no video

我正在利用媒体角色播放录像。 它只播放视听,而不是录像。 是否有任何帮助? 我的法典如下。

public class VideoViewApplication extends Application {

    @Override
    public void onCreate() {
    }

    @Override
    public void onTerminate() {
    }
}


public class VideoViewDemo extends Activity implements 

    OnErrorListener,OnBufferingUpdateListener, OnCompletionListener,
    MediaPlayer.OnPreparedListener, SurfaceHolder.Callback  {

    private static final String TAG = "VideoViewDemo";

    private MediaPlayer mp;
    private EditText mPath;  
    private SurfaceHolder holder;

    private ImageButton mPlay;
        private ImageButton mPause;
    private ImageButton mReset;
    private ImageButton mStop;
    private String current;
    private SurfaceView mPreview;


    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);
        mPreview = (SurfaceView) findViewById(R.id.surface);

        mPath = (EditText) findViewById(R.id.path);
        mPath.setText("rtsp://video2.americafree.tv/AFTVHorrorH26496.sdp");

        mPlay = (ImageButton) findViewById(R.id.play);
        mPause = (ImageButton) findViewById(R.id.pause);
        mReset = (ImageButton) findViewById(R.id.reset);
        mStop = (ImageButton) findViewById(R.id.stop);


        mPlay.setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                playVideo();
            }
        });
        mPause.setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                if (mp != null) {
                    mp.pause();
                }
            }
        });
        mReset.setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                if (mp != null) {
                    mp.seekTo(0);
                }
            }
        });
        mStop.setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                if (mp != null) {
                    current = null;
                    mp.stop();
                    mp.release();
                }
            }
        });

        // getWindow().setFormat(PixelFormat.TRANSPARENT);
        holder = mPreview.getHolder();
        holder.addCallback(this);
        holder.setFixedSize(100, 100);

        runOnUiThread(new Runnable(){
            public void run(){
                playVideo();
            }
        });
    }

    private void playVideo() {
        try {
            final String path = mPath.getText().toString();
            Log.v(TAG, "path: " + path);

            if (path.equals(current) && mp != null) {
                mp.start();
                return;
            }
            current = path;

            mp = new MediaPlayer();
            mp.setOnErrorListener(this);
            mp.setOnBufferingUpdateListener(this);
            mp.setOnCompletionListener(this);
            mp.setOnPreparedListener(this);
            mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mp.setScreenOnWhilePlaying(true);

            mp.setDisplay(mPreview.getHolder());
            mp.setDataSource(path);
            mp.prepare();

            Log.v(TAG, "Duration: ===>" + mp.getDuration());
            mp.start();

        } catch (Exception e) {
            Log.e(TAG, "error: "+ e.getMessage(), e);
            if (mp != null) {
                mp.stop();
                mp.release();
            }
        }
    }

    public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
        Log.d(TAG, "surfaceChanged called");
    }

    public void surfaceCreated(SurfaceHolder arg0) {
        Log.d(TAG, "surfaceCreated called");
    }

    public void surfaceDestroyed(SurfaceHolder arg0) {
        Log.d(TAG, "surfaceDestroyed called");
    }

    public void onPrepared(MediaPlayer arg0) {
        Log.d(TAG, "onPrepared called");
    }

    public void onCompletion(MediaPlayer arg0) {
        Log.d(TAG, "onCompletion called");
    }

    public void onBufferingUpdate(MediaPlayer mediaPlayer, int percent) {
        Log.d(TAG, "onBufferingUpdate called --->   percent:" + percent);
    }

    public boolean onError(MediaPlayer mediaPlayer, int what, int extra) {
        Log.e(TAG, "onError---> what:"+what+"   extra:"+extra);
        if (mediaPlayer != null) {
            mediaPlayer.stop();
            mediaPlayer.release();
        }
        return true;
    }


}



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
        >
    <EditText android:id="@+id/path"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
            />
    <SurfaceView
            android:id="@+id/surface"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
    </SurfaceView>

    <LinearLayout
            android:orientation="horizontal"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            >
        <ImageButton android:id="@+id/play"
                     android:layout_height="wrap_content"
                     android:layout_width="wrap_content"
                     android:src="@drawable/play"/>
        <ImageButton android:id="@+id/pause"
                     android:layout_height="wrap_content"
                     android:layout_width="wrap_content"
                     android:src="@drawable/pause"/>
        <ImageButton android:id="@+id/reset"
                     android:layout_height="wrap_content"
                     android:layout_width="wrap_content"
                     android:src="@drawable/reset"/>
        <ImageButton android:id="@+id/stop"
                     android:layout_height="wrap_content"
                     android:layout_width="wrap_content"
                     android:src="@drawable/stop"/>
    </LinearLayout>
</LinearLayout>
问题回答

我有这个问题,并通过采用这一折旧方法确定类型来解决。

holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

值得尝试,如果你工作的话,你可以调查为什么会自动确定哪类。

我也存在同样的问题,因为地表没有准备好 back照。

你们应当从地表(Created)手里尝试并打电话。

public void surfaceCreated(SurfaceHolder holder) {
        runOnUiThread(new Runnable(){
            public void run(){
                playVideo();
            }
        });
}

我有过这个问题,并通过在我的释放职能中添加可见的线,来解决这个问题:

  public void release() {
    if (mMediaPlayer != null) {
    setVisibility(View.GONE);
      mMediaPlayer.reset();
      mMediaPlayer.release();
      mMediaPlayer = null;
      mCurrentState = STATE_IDLE;}
  }

在准备职能方面,可以发现:

   videoView.setOnPreparedListener(new OnPreparedListener() {
            public void onPrepared(MediaPlayer mp) {
                audio=false; video=false; int ty=mp.getTrackInfo().length;
                for (int i=0; i<ty;i++)
                {
                    if (mp.getAudioTrack()>-1) {audio=true;}
                    if (mp.getVideoTrack()>-1) {video=true;}
                }

                if (((audio==false)&&(skip==true))||((video==false)&&(skip2==true))||((video==true)&&(skip4==true))) 
                {   notifybar("...");
                    nexttr();} else {
                if (vis==true) {
                if (video==false) {
                    if (mVisualizerView.getVisibility()!=View.VISIBLE) {mVisualizerView.setVisibility(View.VISIBLE);}
                        mVisualizerView.link(videoView.getAudioSessionId());
                        vis2=true;
                        } else if (vis2==true){
                       mVisualizerView.release();
                       mVisualizerView.setVisibility(View.GONE);
                      vis2=false;
                        }}
                //this
                if (video==true) {
                if (videoView.getVisibility()!=View.VISIBLE) {videoView.setVisibility(View.VISIBLE);}
                } else {if (videoView.getVisibility()!=View.INVISIBLE) {videoView.setVisibility(View.INVISIBLE);}
                }




相关问题
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 ...

热门标签