java - 在选项卡式活动中打开新片段时播放声音
问题描述
我想在我的选项卡式活动中播放声音。每当滑动屏幕/片段并打开新的屏幕/片段时,都应该播放声音。但这并没有发生。
public static class PlaceholderFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
private static final String ARG_SECTION_NUMBER = "section_number";
public PlaceholderFragment() {
}
/**
* Returns a new instance of this fragment for the given section
* number.
*/
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
/* TextView textView = (TextView) rootView.findViewById(R.id.section_label);
textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));*/
final MediaPlayer playmysnake=MediaPlayer.create(getActivity(),R.raw.rattlesnakerattle);
playmysnake.start();
return rootView;
}
}
解决方案
推荐阅读
- flutter - 如何在 Flutter 中的图像上添加水印文本?
- javascript - 根据特定 ID 显示隐藏
- unit-testing - 错误断言包含且等于未按预期工作
- python - ASCII 环绕与凯撒密码
- java - 覆盖过渡动画不适用于针对 api 30 android
- ios - Swift - 条件绑定的初始化程序必须具有 Optional 类型,而不是 'PHFetchResult
' - javascript - 会话断开后重新连接到 Laravel Echo 服务器
- python - 需要从一个函数中创建一个列表
- javascript - page.type() 内 page.evaluate()
- amazon-web-services - AWS CLI 生成一个文本文件?