当前位置: 代码迷 >> Android >> SurfaceView播放视频时只有声音没有图片解决方案
  详细解决方案

SurfaceView播放视频时只有声音没有图片解决方案

热度:65   发布时间:2016-05-01 21:21:50.0
SurfaceView播放视频时只有声音没有图片
如题;
代码如下:

videoplayer.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" >
<SeekBar 
  android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/skb_video"
  />
<SurfaceView 
android:id="@+id/vdoplayer"
android:layout_width="wrap_content" 
android:layout_height="200dp"
android:layout_gravity="center"
/>
<LinearLayout 
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/vdoplayer"
android:id="@+id/videocontrol"
>
<Button 
android:id="@+id/cmd_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="250dp"
android:layout_marginLeft="200dp"
android:text="@string/play"
/>
<Button 
android:id="@+id/cmd_pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="250dp"
android:layout_toRightOf="@id/cmd_play"
android:text="@string/pause"
/>
</LinearLayout>
   
</FrameLayout>

VideoPlayer.java

package www.lemon.mine;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.SeekBar;

public class VideoPlayer extends Activity implements Callback,OnClickListener{
  /** Called when the activity is first created. */

private Button cmd_play =null;
private Button cmd_pause = null;
private Boolean isChanging = true;

private MediaPlayer mp =null;
private SurfaceView surfaceView;
private SurfaceHolder surfaceHolder;
private Timer mTimer;
private TimerTask mTimerTask;

private LinearLayout ll = null;
private SeekBar skb_video = null;
private static final String tag = "mine";

  @Override
  public void onCreate(Bundle icicle) {
  super.onCreate(icicle);
   
  requestWindowFeature(Window.FEATURE_NO_TITLE);//隐藏标题栏
  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
  WindowManager.LayoutParams.FLAG_FULLSCREEN);//隐藏状态栏  
   
  setContentView(R.layout.videoplayer);//设置布局
   
  skb_video = (SeekBar)findViewById(R.id.skb_video);//进度条
  cmd_play = (Button)findViewById(R.id.cmd_play);//播放按钮
  cmd_play.setOnClickListener(this);
  cmd_pause = (Button)findViewById(R.id.cmd_pause);//暂停按钮
  cmd_pause.setOnClickListener(this);
   
Bundle bunde = this.getIntent().getExtras();
  相关解决方案