我有一个播放视频的片段,我启动了我的应用程序,一切顺利,但当我按下后退按钮并选择另一个视频文件播放时,我的视图不播放视频。
VideoActivity
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
A=this;
th = Thread.currentThread();
// OBTER URL DO VÍDEO
Bundle extras = getIntent().getExtras();
if (extras != null)
_videoURL = extras.getString("CAMINHO_ARQUIVO");
if (savedInstanceState == null)
{
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
public static class PlaceholderFragment extends Fragment
{
static private final int BUFFER_SIZE = 700;// Mb
static private final int NUM_FILES = 20;// Count files in cache dir
public PlaceholderFragment()
{}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.fragment_video, container, false);
frame1 = rootView.findViewById(R.id.frame1);
textureView = (VideoPlayer) rootView.findViewById(R.id.textureView1);
textProgress = (TextView) rootView.findViewById(R.id.textView1);
textureView.setVideoPath(_videoURL);
textureView.setMediaController(new mediac(A, frame1));
textureView.setSeekListener(new VideoPlayer.SeekListener()
{
@Override
public void onSeek(int msec)
{
//if (proxy != null)
//{
//proxy.seek = true;
//} // more speed for seeking
}
@Override
public void onSeekComplete(MediaPlayer mp)
{}
});
textureView
.setOnPreparedListener(new MediaPlayer.OnPreparedListener()
{
@Override
public void onPrepared(final MediaPlayer mp)
{
textureView.start();
}
});
return rootView;
}
答案 0 :(得分:1)
就我在代码中看到的那样,如果savedInstanceState
为空,则创建片段。因此,如果活动未被正确销毁,您将使用相同的片段。
相反,请从onCreate()
中删除此部分,并在每次导航到VideoActivity时创建片段。