当前位置:  开发笔记 > 编程语言 > 正文

VideoView不在RecyclerView中播放视频或音频

如何解决《VideoView不在RecyclerView中播放视频或音频》经验,为你挑选了0个好方法。

嗨,我正在尝试创建一个视频日记片段,其中包含每个列表项中包含标题,心情和视频的recyclerview.由于某种原因,视频视图甚至没有显示出来.videofilePath正确保存,我已经检查了println语句.我没有收到任何错误,但它完全崩溃了.下一个列表项在视频显示之前开始.

这是我的ViewHolder类

public class JournalViewHolder extends RecyclerView.ViewHolder{
private TextView title;
private TextView mood;
private VideoView mVideoView;
MediaController mMediaController;
Context mContext;

public JournalViewHolder(View view, Context context){
    super(view);
    mContext = context;
    title = (TextView)view.findViewById(R.id.JournalTitle);
    mood = (TextView)view.findViewById(R.id.JournalMood);
    mVideoView = (VideoView)view.findViewById(R.id.JournalVideo);
    mMediaController = new MediaController(context);
}

public void bind(JournalEntry journalEntry){
    title.setText(journalEntry.getTitle());
    mood.setText(journalEntry.getMood());
    if(journalEntry.getVideoFileName() != null){
        Uri uri  = Uri.parse(journalEntry.getVideoFileName());
        mVideoView.setVideoURI(uri);
        mVideoView.requestFocus();
        mVideoView.setMediaController(mMediaController);
        mVideoView.setZOrderOnTop(true);
        mVideoView.start();
    }
}

}

这是我的适配器类

public class JournalRecyclerViewAdapter extends RecyclerView.Adapter {

私人名单mJournalEntries; private Context mContext;

public JournalRecyclerViewAdapter(List entries, Context context){
    mJournalEntries = entries;
    mContext = context;
}

@Override
public JournalViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    View view = inflater.inflate(R.layout.journal_list_items, parent, false);
    JournalViewHolder holder = new JournalViewHolder(view, mContext);

    return holder;
}

@Override
public void onBindViewHolder(JournalViewHolder holder, int position) {
    JournalEntry entry = mJournalEntries.get(position);
    holder.bind(entry);
}

@Override
public int getItemCount() {
    return mJournalEntries.size();
}

}

这是我的课程,它启动项目列表和recyclerview

public class JournalView extends FragmentLoggingLifeCycler {
private RecyclerView mRecyclerView;
DataAccess mDataAccess;
List mEntryList;
public static final String USERNAME_KEY = "username";
public static final String PASSWORD_KEY = "password";
String password;
String username;
User currentUser;
private Context mContext;

public JournalView() {
    // Required empty public constructor
}

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    mContext = activity.getApplicationContext();
}

@Override
public void onAttach(Context context) {
    super.onAttach(context);
    mContext = context;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_journal_view, container, false);
    Bundle data = getArguments();
    username = data.getString(USERNAME_KEY);
    password = data.getString(PASSWORD_KEY);
    LinearLayoutManager manager = new LinearLayoutManager(getActivity());
    mDataAccess = DataAccess.getDataAccess(container.getContext());
    currentUser = mDataAccess.getLoginUser(username, password);


     mEntryList = mDataAccess.getAllJournals();
        //mDataAccess.mDatabase.delete(Scheme.Journal.NAME, null, null);
//        mEntryList = trimList(mEntryList, currentUser.getUsername());
//        for(int counter = 0; counter < mEntryList.size(); counter++){
//            System.out.println(mEntryList.get(counter).getTitle());
//        }
        mRecyclerView = (RecyclerView)view.findViewById(R.id.JournalList);
        mRecyclerView.setLayoutManager(manager);
        mRecyclerView.setAdapter(new JournalRecyclerViewAdapter(mEntryList, mContext));
        return view;
    }

private static List trimList(List entries, String username){
    List returnedList = new ArrayList<>();

    for(int i = 0; i< returnedList.size(); i++){
        System.out.println(entries.get(i).getUsername()+ ", " +username);
        if(entries.get(i).getUsername().equals(username)){
            returnedList.add(entries.get(i));
        }
    }
    return returnedList;
}

}

现在这里是我的XML文件.


列出项目文件




    
    



    
    



推荐阅读
依然-狠幸福
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有