接下来是video_xml截屏


Android开发 手机测试运行报错2


video.java文件:

1    package com.example.aptx___4869.myapplication17; 
2     
3    import android.content.Intent; 
4    import android.media.MediaPlayer; 
5    import android.media.session.MediaController; 
6    import android.net.Uri; 
7    import android.os.Build; 
8    import android.support.annotation.RequiresApi; 
9    import android.support.v7.app.ActionBar; 
10   import android.support.v7.app.ActionBarActivity; 
11   import android.support.v7.app.AppCompatActivity; 
12   import android.os.Bundle; 
13   import android.view.WindowManager; 
14   import android.widget.VideoView; 
15    
16    
17   public class video extends ActionBarActivity { 
18    
19       VideoView vdv; 
20       int pos=0;//用来记录前次的播放位置 
21    
22    
23       @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) 
24       @Override 
25       protected void onCreate(Bundle savedInstanceState) { 
26           super.onCreate(savedInstanceState); 
27           setContentView(R.layout.activity_video); 
28    
29           getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);//隐藏系统的状态栏 
30           getSupportActionBar().hide();//隐藏Activity的标题栏 
31    
32           setContentView(R.layout.activity_video);//以上2项设置必须在本方法之前调用 
33    
34           getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);//保持屏幕一直开着不会休眠 
35    
36    
37           Intent it=getIntent();//获取传入的Intent对象 
38           Uri uri= Uri.parse(it.getStringExtra("uri"));//获取要播放视频的Uri 
39           if(savedInstanceState!=null)//如果是因为旋转而重新启动Activity 
40    
41               pos=savedInstanceState.getInt("pos",0);//获取旋转前视频的播放位置 
42    
43           vdv=(VideoView)findViewById(R.id.videoView);//获取界面的VideoView组件 
44           //MediaController mediaCtrl = new MediaController(this);//建立播放控制对象 
45          // vdv.setMediaController(mediaCtrl);//设置播放控制对象 
46    
47           vdv.setVideoURI(uri);//设置要播放视频的Uri 
48       } 
49    
50       protected void onResume(){//当Activity启动或由暂停状态回到互动状态 
51    
52           super.onResume(); 
53           vdv.seekTo(pos);//移动到pos位置 
54           vdv.start();//开始播放 
55       } 
56    
57       protected void onPause(){//当Activity进入到暂停状态时 
58           super.onPause(); 
59           pos=vdv.getCurrentPosition();//储存播放位置 
60           vdv.stopPlayback();//停止播放 
61    
62       } 
63    
64       protected void onSaveInstanceState(Bundle outState){ 
65    
66           super.onSaveInstanceState(outState); 
67           outState.putInt("pos",pos);//将onPause()中所获取的播放位置储存到bundle 
68       } 
69   } 
70   

manifest.xml文件


1    <?xml version="1.0" encoding="utf-8"?> 
2    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
3        package="com.example.aptx___4869.myapplication17"> 
4         
5     
6        <application 
7            android:allowBackup="true" 
8            android:icon="@mipmap/ic_launcher" 
9            android:label="@string/app_name" 
10           android:roundIcon="@mipmap/ic_launcher_round" 
11           android:supportsRtl="true" 
12           android:theme="@style/AppTheme"> 
13           <activity android:name=".MainActivity"> 
14               <intent-filter> 
15                   <action android:name="android.intent.action.MAIN" /> 
16    
17                   <category android:name="android.intent.category.LAUNCHER" /> 
18               </intent-filter> 
19           </activity> 
20           <activity android:name=".video"></activity> 
21       </application> 
22    
23   </manifest>

请教一下哪里出问题了,一直没搞明白

相关文章:

  • 2021-07-24
  • 2022-12-23
  • 2021-12-23
  • 2021-11-25
  • 2022-02-01
  • 2021-06-25
  • 2021-10-28
猜你喜欢
  • 2021-05-16
  • 2021-11-15
  • 2022-12-23
  • 2022-01-21
  • 2021-06-25
  • 2021-12-11
  • 2022-12-23
相关资源
相似解决方案