嗨所有我是Android的新手,我将Controller添加到VideoView。为什么我会低于错误。
Error:(51, 41) error: no suitable constructor found for MediaController(ClassNAme )
constructor MediaController.MediaController(Context) is not applicable
(actual argument ClassNAme cannot be converted to Context by method invocation conversion)
constructor MediaController.MediaController(Context,boolean) is not applicable
(actual and formal argument lists differ in length)
constructor MediaController.MediaController(Context,AttributeSet) is not applicable
(actual and formal argument lists differ in length)
****请在下面找到以下代码我的ClassName如下****
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_picturedetail, container, false);
Bundle b = getArguments();
Drawable d;
am = getActivity().getAssets();
PictDictDetails pd = (PictDictDetails) b.getSerializable("pictobj");
ImageView iv = (ImageView)v.findViewById(R.id.iv_picture);
VideoView vi = (VideoView)v.findViewById(R.id.iv_video);
TextView tv = (TextView)v.findViewById(R.id.tv_picture_name);
String path = pd.getPath();
MediaController mediaController1 = new MediaController(this);
mediaController1.setAnchorView(vi);
vi.setMediaController(mediaController1);
String uri = path;
vi.setVideoURI(Uri.parse(uri));
vi.start();
请查找完整代码
public class ClassName extends Fragment {
AssetManager am;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_picturedetail, container, false);
Bundle b = getArguments();
Drawable d;
am = getActivity().getAssets();
PictDictDetails pd = (PictDictDetails) b.getSerializable("pictobj");
ImageView iv = (ImageView)v.findViewById(R.id.iv_picture);
VideoView vi = (VideoView)v.findViewById(R.id.iv_video);
TextView tv = (TextView)v.findViewById(R.id.tv_picture_name);
String path = pd.getPath();
String name = pd.getName();
String uri = path;
vi.setVideoURI(Uri.parse(uri));
vi.start();
MediaController mediaController1 = new MediaController(this);
mediaController1.setAnchorView(vi);
vi.setMediaController(mediaController1);
try
{
InputStream ims = am.open(path);
d = Drawable.createFromStream(ims, null);
iv.setImageDrawable(d);
}
catch(IOException e)
{
e.printStackTrace();
}
tv.setText(name);
return v;
}
@Override
public void onDestroyView() {
super.onDestroyView();
}
}
答案 0 :(得分:1)
在代码中的某处(java文件之一),您创建了一个名为" ClassNAme"的自定义类。我认为您已尝试使用mediaController构造函数来创建您的实例。
您应该为此类声明自己的自定义构造函数,除非它是媒体控制器(在这种情况下,请确保它是使用extends的MediaController的子类)。