我制作了一个包含4个标签的应用程序:
我已经制作了MainActivity类,其中使用FragmentTabHost类id作为显示选项卡。
public class MainActivity extends FragmentActivity{
private FragmentTabHost mTabHost;
private FragmentTabHost mTabHostabove;
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.activity_main);
mTabHost = (FragmentTabHost)findViewById(R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.tabcontent);
mTabHost.addTab(mTabHost.newTabSpec("Vedio").setIndicator("Vedio",getResources().getDrawable(R.drawable.ic_launcher)),FragmentTab.class,null);
mTabHost.addTab(mTabHost.newTabSpec("Virtual Lab").setIndicator("Virtual Lab"),FragmentTab.class,null);
mTabHost.addTab(mTabHost.newTabSpec("Edit Vedio").setIndicator("Edit Vedio"),FragmentTab.class,null);
mTabHost.addTab(mTabHost.newTabSpec("Help").setIndicator("Help1"),FragmentTab.class,null);
mTabHostabove = (FragmentTabHost)findViewById(R.id.tabhostabove);
mTabHostabove.setup(this, getSupportFragmentManager(), R.id.tabcontent);
mTabHostabove.addTab(mTabHostabove.newTabSpec("Logo").setIndicator("Logo"),FragmentTab.class,null);
mTabHostabove.addTab(mTabHostabove.newTabSpec("Vedio Url ").setIndicator("Vedio Url",getResources().getDrawable(R.drawable.ic_launcher)),FragmentTab.class,null);
}
}
我还制作了扩展Fragment的FragmentTab类。
这是代码:
public class FragmentTab extends Fragment {
private TextView tv;
private VideoView mVideoView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_layout, container, false);
tv = (TextView) v.findViewById(R.id.text);
mVideoView = (VideoView)v.findViewById(R.id.vedioview);
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
String path1="http://commonsware.com/misc/test2.3gp";
MediaController mc = new MediaController(getActivity());
mc.setAnchorView(mVideoView);
mc.setMediaPlayer(mVideoView);
mVideoView.setMediaController(mc);
mVideoView.requestFocus();
// mVideoView.setVideoURI(Uri.parse("android.resource://" +getActivity().getApplicationContext().getPackageName() +"/"+R.raw.song));
mVideoView.setVideoURI(Uri.parse(path1));
mc.show();
mVideoView.start();
} catch (Exception e) {
}
}
});
String tag = this.getTag();
if (tag == "Vedio") {
tv.setText("play vedio");
}
if (tag == "Edit Vedio") {
tv.setText("want to Edit Vedio !!!!!!!");
}
if (tag == "Help") {
tv.setText("do u want help !!!!!!!");
}
if (tag == "Virtual Lab") {
tv.setText("Enter Virtual lab !!!!!!!");
}
return v;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
}
我坚持在点击视频选项卡上播放视频 任何人都可以解决它。我搜索了3天,但我还没有找到解决方案。视频声音即将来临,但视频不播放。
答案 0 :(得分:0)
并非所有设备都支持所有视频编解码器。
我遇到了同样的问题:我使用的是mp4格式,分辨率为1280x720。所有设备(例如HTC Wildfire S)都不支持此视频格式。将分辨率更改为480x360后,所有设备都会显示视频。
此链接可以帮助您: http://developer.android.com/guide/appendix/media-formats.html