android模拟器中播放视频(有声无影等问题的解决)

      今天按照《Android应用开发揭秘》中的代码做了个播放视频的小例子,播放后发现有声无音,发现是视频分辨率过大造成的。

使用格式工厂工具把MP4转换一下就可以了。

转换的配置如图



转换后的文件属性如下:




那个帧速率是重点,要调低。


相关的代码:

package com.yarin.android.Examples_07_03;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.VideoView;
import android.media.*;
import android.view.Window;
import android.view.WindowManager;
public class Activity01 extends Activity
{
	private static final String TAG="VideoView";
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
        //不要标题
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //设置成全屏模式
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        		WindowManager.LayoutParams.FLAG_FULLSCREEN);
        //强制为横屏
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

		setContentView(R.layout.main);
		

	
		final VideoView videoView = (VideoView) findViewById(R.id.VideoView01);
		
		
		Button PauseButton = (Button) this.findViewById(R.id.PauseButton);
		Button LoadButton = (Button) this.findViewById(R.id.LoadButton);
		Button PlayButton = (Button) this.findViewById(R.id.PlayButton);
		
		
		LoadButton.setOnClickListener(new OnClickListener() 
		{
			public void onClick(View arg0)
			{
								
				videoView.setVideoPath("/mnt/sdcard/aaoceans-clip.mp4");				
				videoView.setMediaController(new MediaController(Activity01.this));
				videoView.requestFocus();
			}
		});
		
		PlayButton.setOnClickListener(new OnClickListener() 
		{
			public void onClick(View arg0)
			{
				
				Log.v(TAG,"start");								
				videoView.start();
				Log.v(TAG,"start OK");
			}
		});
		
		PauseButton.setOnClickListener(new OnClickListener() 
		{
			public void onClick(View arg0)
			{				
				videoView.pause();
			}
		});
	}
}



main.xml中要添加

    	<VideoView 
    	android:id="@+id/VideoView01" 
    	android:layout_width="fill_parent"
   	android:layout_height="fill_parent"
     />
  	<Button android:id="@+id/LoadButton"
    	android:layout_width="80px"
    	android:layout_height="wrap_content"
    	android:text="装载"
  	android:layout_x="30px"
  	android:layout_y="300px"
    	/>  
  	<Button android:id="@+id/PlayButton"
    	android:layout_width="80px"
    	android:layout_height="wrap_content"
    	android:text="播放"
  	android:layout_x="120px"
  	android:layout_y="300px"
    	/>
  	<Button android:id="@+id/PauseButton"
    	android:layout_width="80px"
    	android:layout_height="wrap_content"
    	android:text="暂停"
  	android:layout_x="210px"
  	android:layout_y="300px"
   	/>

VideoView的布局属性要设成fill_parent.




  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值