播放视频VideoView和SurfaceView(它是父类)(查看api)(更高级的查看vitamio)
来源:互联网 发布:斯芬克 知乎 编辑:程序博客网 时间:2024/05/20 02:21
VideoView
主程序
package com.test.myplayvideo;import android.support.v4.os.EnvironmentCompat;import android.support.v7.app.ActionBarActivity;import android.app.Activity;import android.os.Bundle;import android.os.Environment;import android.provider.MediaStore.Video;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.MediaController;import android.widget.VideoView;public class MainActivity extends Activity implements OnClickListener{ private Button mButtonPlay; private VideoView mVideoView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mButtonPlay=(Button) findViewById(R.id.button_play_video); mButtonPlay.setOnClickListener(this); mVideoView=(VideoView) findViewById(R.id.video_view); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.button_play_video: mVideoView.setVideoPath(Environment.getExternalStorageDirectory() + "/netease/cloudmusic/MV/aa.mp4"); mVideoView.setMediaController(new MediaController(MainActivity.this)); mVideoView.start(); break; default: break; } }}
布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <Button android:id="@+id/button_play_video" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="播放" /> <VideoView android:id="@+id/video_view" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"/></LinearLayout>
SurfaceView
主程序
package com.test.mymediasurfaceview;import android.support.v7.app.ActionBarActivity;import java.io.IOException;import android.app.Activity;import android.media.AudioManager;import android.media.MediaPlayer;import android.media.MediaPlayer.OnPreparedListener;import android.os.Bundle;import android.os.Environment;import android.provider.MediaStore.Audio;import android.view.Menu;import android.view.MenuItem;import android.view.SurfaceView;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class MainActivity extends Activity implements OnClickListener { private Button mButtonPlay; private SurfaceView mSurfaceView; private MediaPlayer player; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mButtonPlay = (Button) findViewById(R.id.button_surface); mSurfaceView = (SurfaceView) findViewById(R.id.surfaceview); mButtonPlay.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.button_surface: if (player == null) { player = new MediaPlayer(); } player.reset(); try { player.setDataSource(Environment.getExternalStorageDirectory() + "/netease/cloudmusic/MV/aa.mp4"); player.setAudioStreamType(AudioManager.STREAM_MUSIC); player.setDisplay(mSurfaceView.getHolder()); player.prepare(); player.setOnPreparedListener(new OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { player.start(); } }); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; default: break; } }}
布局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.test.mymediasurfaceview.MainActivity" > <SurfaceView android:id="@+id/surfaceview" android:layout_width="match_parent" android:layout_height="match_parent" /> <Button android:id="@+id/button_surface" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Play" /></RelativeLayout>
0 0
- 播放视频VideoView和SurfaceView(它是父类)(查看api)(更高级的查看vitamio)
- VideoView和SurfaceView播放视频
- VideoView和SurfaceView视频播放
- 用VideoView和SurfaceView播放视频
- Android视频播放框架Vitamio集成及使用MediaPlayer+SurfaceView、VideoView+MediaController实现播放网络视频
- 视频播放器videoview surfaceview
- Android两种播放视频的方法(SurfaceView、MediaPlayer、SeekBar)和(VideoView、MediaController)等两种方法。
- android 开发视频播放器API----Vitamio API for Android: VideoView
- 多媒体之播放视频——VideoView和MediaPlayer(MediaPlayer和SurfaceView结合)
- Android的视频播放之VideoView与SurfaceView
- Android--使用VideoView播放视频以及VideoView的api
- android 高级之旅 (五) VideoView 和 Vitamio的基本用法
- Android两种播放视频的方法(SurfaceView+MediaPlayer+SeekBar)跟(VideoView+MediaController)
- 视频播放控件SurfaceView与VideoView
- Android-SurfaceView+VideoView视频播放器实例
- 视频播放(VideoView)
- android视频播放(VideoView和MediaController)
- videoView和mediaController视频播放
- 线程等待的几种方式
- iOS 开发之 菜单栏UITabBarController
- 删除表空间报错ORA-00604&ORA-02429解决过程
- Android View坐标getLeft, getRight, getTop, getBottom解惑
- android intent
- 播放视频VideoView和SurfaceView(它是父类)(查看api)(更高级的查看vitamio)
- STL 中的 std::string大小写转换 lowercase、uppercase、Trim、replace、split
- Android 多媒体应用:视频播放之VideoView与SurfaceView
- uva 815
- 【HEOI2014】【BZOJ3613】南园满地堆轻絮
- jquery处理html格式的数据
- android 获取系统时间
- nginx利用fastcgi_cache模块缓存
- Fiddler抓取HTTPs流量