VideoView视频播放器的再打开
2015-06-05 10:04
543 查看
布局文件只有一个VideoView,不再给出。
启动app后,按home键。再按app,或用它打开一个视频文件都会出现一下信息:
“`
多说几句:1.刚发现关闭屏幕也会onPause(),onStop()
2.在手机的最近任务里重启已存在的Activity,不会触发onNewIntent.
只有onRestart(),onStart(),onResume().
/*-------------MainActivity.java-----------*/ package com.example.videoviewtest; import java.io.File; import android.app.Activity; import android.content.Intent; import android.graphics.PixelFormat; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.MediaController; import android.widget.VideoView; public class MainActivity extends Activity { File file = new File(Environment.getExternalStorageDirectory() + "/DCIM/Camera/test2.mp4"); if(file.exists()){ videoView.setVideoPath(file.getAbsolutePath()); videoView.setMediaController(mediaController); mediaController.setMediaPlayer(videoView); videoView.requestFocus(); } // 用于判读这个Activity是用户点击app图标启动的,还是通过点击视频文件后弹出的打开方式打开的。 if(getIntent().getData() != null){ videoView.setVideoURI(getIntent().getData()); } Log.d(TAG, "onCreate"); } @Override protected void onStart() { super.onStart(); Log.d(TAG,"onstart"); }; @Override protected void onResume() { super.onResume(); Log.d(TAG, "onResume"); } @Override protected void onPause() { super.onPause(); Log.d(TAG, "onPause"); }; @Override protected void onStop(){ super.onStop(); Log.d(TAG, "onStop"); } @Override protected void onRestart(){ super.onRestart(); Log.d(TAG, "onRestart"); } /*当Activity的launchMode为singleTop时,在已经有Activity的情况下,点击app或用它打开视频文件把它显示出来(re-launch),会触发onNewInent()*/ @Override protected void onNewIntent(Intent intent) { Log.d(TAG, "onNewIntent"); // 获取文件的uri videoView.setVideoURI(intent.getData()); super.onNewIntent(intent); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } /** 注意:需要用到sdcard,联网等权限时,先配置manifest,省的出现莫名其妙的错误。 */ <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.videoviewtest" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" android:launchMode="singleTop"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> // 打开后缀为mp4的视频文件。 <intent-filter > <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.DEFAULT"/> <data android:mimeType="video/mp4"/> </intent-filter> </activity> </application> </manifest>
启动app后,按home键。再按app,或用它打开一个视频文件都会出现一下信息:
“`
多说几句:1.刚发现关闭屏幕也会onPause(),onStop()
2.在手机的最近任务里重启已存在的Activity,不会触发onNewIntent.
只有onRestart(),onStart(),onResume().
相关文章推荐
- Android实现表情 抓取新浪表情
- 详解Android解析Xml的三种方式——DOM、SAX以及XMLpull
- android开发环境遇到adt无法启动的问题分析及解决方法
- Android开发 旋转屏幕导致Activity重建解决方法
- Android开发技巧之在a标签或TextView控件中单击链接弹出Activity(自定义动作)
- Android开发技巧之ViewStub控件惰性装载
- 分享10个很棒的学习Android开发的网站
- android开发之横向滚动/竖向滚动的ListView(固定列头)
- Android开发技巧之我的菜单我做主(自定义菜单)
- Windows下使用Apache Cordova开发ANDROID之HelloWorld
- 根据根据图片的url怎么取得图片ImageView对象
- [转] ADB server didn't ACK
- android开发的相关链接
- Android数据存储之SharedPreferences 共享首选项/偏好设置
- 基于NDK的Android防破解
- android开发学习如何一体化?从入门到高端开发的路如何走?
- Android入门到精通详解 电子书下载
- --暴走漫画系列--高仿淘宝收货地址(附demo)
- Android开发高手如何炼成?
- Android开发的真正难度并不在技术