Android kako u recyclerview stopirati zvuk

poruka: 2
|
čitano: 641
|
moderatori: Danny_HR, Lazarus Long, XXX-Man, vincimus
1
+/- sve poruke
ravni prikaz
starije poruke gore
6 godina
offline
Android kako u recyclerview stopirati zvuk

Nedavno sam objavio aplikaciju za djecu i problem mi je sto nikako ne uspjevam stopirati zvuk nakon sto kliknem novi zvuk. Znaci paralelno mi sviraa vise zvukova dok ne zavrse. Znam da treba uraditi stop i relese ali nikako ne uspjevam.

Ima li itko link gdje je to objasnjeno?

 

Mogu vam dati i i code od adaptera:

 

A evo vam i link od aplikacije pa ako netko zeli moze i vidjeti problem:

 

https://play.google.com/store/apps/details?id=org.pero.androidd.animalSoundsQuiz

 
0 0 hvala 0
6 godina
offline
Android kako u recyclerview stopirati zvuk

Evo i code od adaptera, medjutim ne znam kako da formatiram code pa malo ruzno izgleda:

 


import android.content.Context;
import android.media.MediaPlayer;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.pero.androidd.animalsoundsforchildren.R;

import java.util.List;


public class ZivotinjeAdapter extends RecyclerView.Adapter<ZivotinjeAdapter.ViewHolder> {

@Override
public ZivotinjeAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Context context = parent.getContext();
LayoutInflater inflater = LayoutInflater.from(context);

// Inflate the custom layout
View contactView = inflater.inflate(R.layout.item_zivotinje, parent, false);

// Return a new holder instance
ViewHolder viewHolder = new ViewHolder(contactView);
return viewHolder;
}

@Override
public void onBindViewHolder(ZivotinjeAdapter.ViewHolder viewHolder, int position) {


Zivotinje zivotinjeIme = mZivotinje.get(position);

// Set item views based on the data model
TextView textView = viewHolder.nameTextView;
textView.setText(zivotinjeIme.getmAnimal_name());


//lodamo slike koristeci Glide
ImageView slika_source = viewHolder.imageView;
Glide.with(slika_source.getContext())
.load((Integer) zivotinjeIme.getmAnimal_slika())
.into(slika_source);



viewHolder.setItem(mZivotinje.get(position));

}


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

public static class ViewHolder extends RecyclerView.ViewHolder {

public ImageView imageView;
public TextView nameTextView;
private Zivotinje mItem;



public void setItem(Zivotinje item) {
this.mItem = item;
}



public ViewHolder(final View itemView) {
super(itemView);

nameTextView = (TextView) itemView.findViewById(R.id.zivotinjaIme_id);
imageView = (ImageView) itemView.findViewById(R.id.slika_id);


//Click event za svaki item
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//pozivamo staticku metdou za reklame iz MainActivity
MainActivity.prikaziReklamu();
final MediaPlayer mediaPlayer = MediaPlayer.create(v.getContext(), mItem.getmSound());
mediaPlayer.start();



//releace media player nakon sto zvuk zavrsi. ZELIM DA URADIM releace nakon sto kliknem novi item iz recycleview
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mediaPlayer.release();

}
});
}
});

}


}

private List<Zivotinje> mZivotinje;

public ZivotinjeAdapter(List<Zivotinje> animals) {
mZivotinje = animals;
}




}

Poruka je uređivana zadnji put sri 8.6.2016 21:03 (kingofthenight).
 
0 0 hvala 0
1
Nova poruka
E-mail:
Lozinka:
 
vrh stranice