Guys, this question: is there any possibility to set the sound when a new record appears in RecyclerView (in my case, this message). There was an attempt to fasten the whole thing to the appearance of a new element on the screen, but the sound also appears just when scrolling correspondence (which was to be expected). The whole thing is tied to the FireBaseRecyclerAdapter.
canPlaySound = false;// разрешено ли воспроизводить звук mFBAdapter = new FirebaseRecyclerAdapter<ChatMessage, FirechatMsgViewHolder>( ChatMessage.class, R.layout.message, FirechatMsgViewHolder.class, mDatabaseReference.child(romName) ) { @Override protected void populateViewHolder(FirechatMsgViewHolder firechatMsgViewHolder, ChatMessage chatMessage, int i) { mProgressBar.setVisibility(ProgressBar.INVISIBLE); if (chatMessage.getUid().equals(mUid)) { firechatMsgViewHolder.setIsSender(true); } else { firechatMsgViewHolder.setIsSender(false); } firechatMsgViewHolder.msgText.setText(chatMessage.getText()); firechatMsgViewHolder.userText.setText(chatMessage.getName()); mUsername = mFirebaseUser.getDisplayName(); if (mPhotoUrl.equals("")) { mPhotoUrl = mFirebaseUser.getPhotoUrl().toString(); } Glide.with(ChatFragment.this). load(chatMessage.getPhotoUrl()).into(firechatMsgViewHolder.userImage); // если при входе в чат все элементы прогруженны - canPlaySound = true; if (canPlaySound) { sp.play(soundIdShot, 1, 1, 0, 0, 1); sp.play(soundIdExplosion, 1, 1, 0, 0, 1); } } }; mFBAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { @Override public void onItemRangeInserted(int positionStart, int itemCount) { super.onItemRangeInserted(positionStart, itemCount); int chatMsgCount = mFBAdapter.getItemCount(); int lastVisiblePosition = mLayoutManager.findLastCompletelyVisibleItemPosition(); if (lastVisiblePosition == -1 || (positionStart >= (chatMsgCount - 1) && lastVisiblePosition == (positionStart - 1))) { mMsgRecyclerView.scrollToPosition(positionStart); } } }); mMsgRecyclerView.setLayoutManager(mLayoutManager); mMsgRecyclerView.setAdapter(mFBAdapter); mUsername = mFirebaseUser.getDisplayName().toString(); canPlaySound = true; 