我第一次学习android所以我开始使用视频播放器。我已经正确编写了代码,但我不知道哪里出错了。
问题是我隐藏导航栏但导航栏的阴影正在显示,导航栏的后退按钮不起作用。某些视频无法全屏播放。它只播放屏幕的一半
这是我的代码
public class VideoList extends AppCompatActivity {
File root;
private ArrayList<File> fileList = new ArrayList<File>();
ListView videolist;
String[] list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_list);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Bundle extras = getIntent().getExtras();
String dir = extras.getString("Dir");
root = new File(dir);
list = new String[3];
File listFile[] = root.listFiles();
videolist = (ListView) findViewById(R.id.videolist);
if (listFile != null && listFile.length > 0) {
for (int i = 0; i < listFile.length; i++) {
if (listFile[i].getName().endsWith(".mp4")
|| listFile[i].getName().endsWith(".avi")
|| listFile[i].getName().endsWith(".mpeg")
|| listFile[i].getName().endsWith(".3gp") || listFile[i].getName().endsWith(".mkv")) {
fileList.add(listFile[i]);
String filePath = listFile[i].getAbsolutePath();
File file = new File(filePath);
}
}
}
list = new String[fileList.size()];
for (int j = 0; j < fileList.size(); j++) {
String temp = fileList.get(j).getAbsolutePath();
list[j] = temp;
Log.v("bbb", j + " " + list[j]);
}
Ticket_adapter adapter = new Ticket_adapter(VideoList.this, list);
videolist.setAdapter(adapter);
videolist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent ii = new Intent(VideoList.this, ViewVideo.class);
ii.putExtra("Fullpath", fileList.get(position).getAbsolutePath());
startActivity(ii);
}
});
}
}
class Ticket_adapter extends ArrayAdapter<String> {
Context context;
String[] list;
Bitmap bMap;
String aaaaa;
LayoutInflater inflater;
public Ticket_adapter(VideoList context, String[] list) {
super(context, R.id.list_item, list);
this.context = context;
this.list = list;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
Log.v("Aa", "" + list[position]);
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_item, null);
}
TextView idtxt = (TextView) convertView.findViewById(R.id.gool);
TextView dur = (TextView) convertView.findViewById(R.id.myImageViewText);
ImageView videol = (ImageView) convertView.findViewById(R.id.abcd);
File abc = new File(list[position]);
idtxt.setText(abc.getName());
Bitmap bMap;
bMap = ThumbnailUtils.createVideoThumbnail(list[position], MediaStore.Video.Thumbnails.MICRO_KIND);
try {
videol.setImageBitmap(bMap);
} catch (Exception e) {
Log.v("DDD", " " + list[position]);
e.printStackTrace();
}
MediaPlayer mp = MediaPlayer.create(context, Uri.parse(list[position]));
int duration = mp.getDuration();
mp.release();
/*convert millis to appropriate time*/
if (TimeUnit.MICROSECONDS.toHours(duration) == 0) {
aaaaa = String.format("%d:%d",
TimeUnit.MILLISECONDS.toMinutes(duration),
TimeUnit.MILLISECONDS.toSeconds(duration) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration)));
} else {
aaaaa = String.format("%d:%d:%d", TimeUnit.MILLISECONDS.toHours(duration),
TimeUnit.MILLISECONDS.toMinutes(duration) % 60,
TimeUnit.MILLISECONDS.toSeconds(duration) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration)));
}
Log.v("ads", "" + aaaaa);
dur.setText(aaaaa);
return convertView;
}
}
这里我附上了我的视频播放器的截图 enter image description here 这里在底部和导航栏阴影正在显示。我想删除那个shodaow。导航栏后退按钮不起作用 和我的ViewVideo.java
public class ViewVideo extends AppCompatActivity {
String dir;
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_video);
Bundle extras = getIntent().getExtras();
dir = extras.getString("Fullpath");
File aa = new File(dir);
Log.v("AAAA", dir);
VideoView videoView = (VideoView) findViewById(R.id.videoView1);
try {
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
Uri uri = Uri.parse(dir);
videoView.setMediaController(mediaController);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
}
此处在底部和导航栏上显示阴影。我想删除该阴影。导航栏中的后退按钮不起作用。 请解决我的问题我上周得到解决方案。
提前致谢