我的片段类中有一个VideoView。还有一个按钮,可让您播放和暂停视频。当我点击按钮播放视频时,我想要视频全屏显示。我怎么能以编程方式而不是通过XML来做到这一点?
以下是我片段的来源:
public class Test extends Fragment
{
private VideoView vid;
private Button playpause1;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState)
{
root = (ViewGroup) inflater.inflate(R.layout.test, null);
vid = (VideoView) root.findViewById(R.id.videoView1);
vid.requestFocus();
vid.setVideoURI(Uri.parse("my_path"));
playpause1 = (Button) root.findViewById(R.id.playpause1);
playpause1.setText(R.string.buffering);
playpause1.setEnabled(false);
playpause1.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
if vid.isPlaying())
{
vid.pause();
}
else
{
vid.start();
}
}
});
vid.setOnPreparedListener(new OnPreparedListener()
{
@Override
public void onPrepared(MediaPlayer mp)
{
playpause1.setEnabled(true);
mp.setOnInfoListener (new MediaPlayer.OnInfoListener()
{
@Override
public boolean onInfo (MediaPlayer mp, int what, int extra)
{
if (what == MediaPlayer.MEDIA_INFO_BUFFERING_START)
{
playpause1.setEnabled(false);
}
if(what == MediaPlayer.MEDIA_INFO_BUFFERING_END)
{
playpause1.setEnabled(true);
}
return false;
}
});
}
});
}
}
答案 0 :(得分:0)
使用自己的布局(包含完整尺寸的视频)创建一个新片段。
新片段应该获得当前播放状态:
public static FullVideoFragment newInstance(final long playedDuration)
{
final FullVideoFragment fragment = new FullVideoFragment();
final Bundle bundle = new Bundle();
bundle.putLong("playedDuration", playedDuration);
fragment.setArguments(bundle);
return fragment;
}
@Override
public void onActivityCreated(final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
this.playDuration = getArguments().getLong("playedDuration");
initializeViews(); //get video URI...
}
在片段的clickListener中:使用FragmentManager添加完整大小的视频片段并传递播放持续时间。
将新的全尺寸片段搜索到给定的playingDuration并播放视频。