Play/pause buttons in Listview are not updating - android

I am new on Android. I have a listview, which have image, text and play/pause button. When I click on a play button in a row and then click on the play button in another row, the background of both buttons remain pause. So I want that when I click on play button in a row and then click on the play button in another row, the background of first button should change to play and background of second should remain pause. Thanks in advance.
public class MyListAdapter extends ArrayAdapter<String> {
private String[] gelenurl;
List<String> gelen_ad;
public static MediaPlayer mPlayer= new MediaPlayer();
private int layout;
public MyListAdapter(Context context, int resource, List<String> objects, String[] arr) {
super(context, resource, objects);
layout=resource;
gelenurl=arr;
gelen_ad=objects;
}
#NonNull
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder mainViewholder;
if(convertView==null) {
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView=inflater.inflate(layout, parent, false);
mainViewholder= new ViewHolder();
convertView.setTag(mainViewholder);
}
else {
mainViewholder = (ViewHolder) convertView.getTag();
}
mainViewholder.img = (ImageView) convertView.findViewById(R.id.list_item_thumbnail);
mainViewholder.img.setImageResource(R.drawable.ic_radio);
mainViewholder.title = (TextView) convertView.findViewById(R.id.list_item_text);
mainViewholder.title.setText(getItem(position));
mainViewholder.button = (ImageButton) convertView.findViewById(R.id.list_item_btn);
mainViewholder.button.setImageResource(R.drawable.transparent_play);
mainViewholder.button.setBackgroundColor(Color.WHITE);
mainViewholder.button.setVisibility(View.VISIBLE);
mainViewholder.stop_button = (ImageButton) convertView.findViewById(R.id.list_item_stop_btn);
mainViewholder.stop_button.setImageResource(R.drawable.transparent_stop);
mainViewholder.stop_button.setBackgroundColor(Color.WHITE);
final ViewHolder vh = mainViewholder;
vh.stop_button.setVisibility(View.INVISIBLE);
mainViewholder.button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
vh.button.setVisibility(View.INVISIBLE);
vh.stop_button.setVisibility(View.VISIBLE);
try {
radioLinks(gelenurl[position]);
} catch (IOException e) {
e.printStackTrace();
}
}
public void radioLinks(String city) throws IOException {
if(mPlayer.isPlaying()) {
mPlayer.stop();
mPlayer.reset();
}
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mPlayer.setDataSource(city);
mPlayer.prepareAsync();
mPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mPlayer.start();
}
});
}
});
mainViewholder.stop_button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
vh.button.setVisibility(View.VISIBLE);
vh.stop_button.setVisibility(View.INVISIBLE);
mPlayer.stop();
mPlayer.reset();
}
});
return convertView;
}
}

You will want to track the currently playing song with a member variable. Something like private String currentCity = null. Inside the onClick handler for play, you'll set that to the selected item, and call notifyDataSetChanged to tell the adapter to refresh everything. Inside the stop callback, you'll probably need to set currentCity = null after stopping and again call notifyDataSetChanged()
try {
currentCity = gelenurl[position];
radioLinks(currentCity);
notifyDataSetChanged();
} catch (IOException e) {
e.printStackTrace();
}
You want to use that information inside getView() to decide what to show.
mainViewholder.img = (ImageView) convertView.findViewById(R.id.list_item_thumbnail);
mainViewholder.img.setImageResource(R.drawable.ic_radio);
mainViewholder.title = (TextView) convertView.findViewById(R.id.list_item_text);
mainViewholder.title.setText(getItem(position));
mainViewholder.button = (ImageButton) convertView.findViewById(R.id.list_item_btn);
mainViewholder.button.setImageResource(R.drawable.transparent_play);
mainViewholder.button.setBackgroundColor(Color.WHITE);
...
if ( getItem(position) == currentCity ) {
// show stop button
} else {
/// show play button
}

Related

Changing of Listview Button State when pressed for position

I have a Listview, in which every row has play button. If i clicked on First Play Button it changes to pause but if i pressed second row play button,then first will remain in pause state but i want that if any of button is pressed then the previous button back to its play state and the clicked one changes to pause.
Code is below.
public class RingsAdapter extends BaseAdapter {
private Context context;
private ArrayList<Ringsinfo> data;
private SqlLiteDbHelper db;
private MediaPlayer mediaPlayer;
int pause_button_position = -1;
public RingsAdapter(Context mContext) {
data = new ArrayList<Ringsinfo>();
context = mContext;
initDatabase(context);
mediaPlayer = new MediaPlayer();
}
private void initDatabase(Context c) {
db = new SqlLiteDbHelper(c);
try {
db.CopyDataBaseFromAsset();
db.openDataBase();
} catch (IOException e) {
e.printStackTrace();
}
}
public void AddAll(ArrayList<Ringsinfo> listperson) {
data.clear();
data.addAll(listperson);
notifyDataSetChanged();
}
#Override
public int getCount() {
return this.data.size();
}
#Override
public Object getItem(int position) {
return (Ringsinfo) this.data.get(position);
}
#Override
public long getItemId(int position) {
return (long) position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
HolderView mHolderView;
if (convertView == null) {
mHolderView = new HolderView();
convertView = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.row_ringtone_list, parent, false);
mHolderView.btnPlay = (Button) convertView.findViewById(R.id.btnPlay);
mHolderView.btnSetting = (Button) convertView.findViewById(R.id.btnSetting);
mHolderView.tvRingName = (TextView) convertView.findViewById(R.id.tvRingName);
convertView.setTag(mHolderView);
} else {
mHolderView = (HolderView) convertView.getTag();
}
mHolderView.tvRingName.setText(((Ringsinfo) this.data.get(position)).name);
mHolderView.btnSetting.setOnClickListener(new RingDetails(position));
mHolderView.btnPlay.setOnClickListener(new playRingtone(position));
if (position != pause_button_position)
mHolderView.btnPlay.setBackgroundResource(R.mipmap.play);
return convertView;
}
class RingDetails implements View.OnClickListener {
final int val$position;
RingDetails(int i) {
this.val$position = i;
}
public void onClick(View view) {
Intent intent = new Intent(context, RingDetailActivity.class);
intent.putExtra("calls", ((Ringsinfo) data.get(this.val$position)).content);
intent.putExtra("heading", ((Ringsinfo) data.get(this.val$position)).name);
context.startActivity(intent);
}
}
class playRingtone implements View.OnClickListener {
int val$position;
playRingtone(int i) {
val$position = i;
}
public void onClick(View view) {
if (mediaPlayer.isPlaying()) {
mediaPlayer.pause();
view.setBackgroundResource(R.mipmap.play);
} else {
view.setBackgroundResource(R.mipmap.pause);
pause_button_position = val$position;
mediaPlayer.start();
}
mediaPlayer.reset();
mediaPlayer = MediaPlayer.create(context, new Builder().scheme("android.resource").authority(context.getPackageName()).appendPath(String.valueOf(context.getResources().getIdentifier(((Ringsinfo) data.get(val$position)).content + BuildConfig.FLAVOR, "raw", context.getPackageName()))).build());
mediaPlayer.start();
}
}
private class HolderView {
private Button btnPlay, btnSetting;
private TextView tvRingName;
}
public void Stop() {
if (mediaPlayer != null && mediaPlayer.isPlaying()) {
mediaPlayer.reset();
mediaPlayer.stop();
mediaPlayer.release();
}
}}
You need to write else condition in your Adapter where you change your background for ImageView
if (position != pause_button_position)
mHolderView.btnPlay.setBackgroundResource(R.mipmap.play);
else
mHolderView.btnPlay.setBackgroundResource(R.mipmap.pause);
Also, It would be good if you manage one Boolean list in Adapter to manager your play pause button.
Like your Boolean list is same size of your ArrayList. once user click on 1st play button then you need to set true at 1st position of Boolean List and rest of are false. Same way if user click on 2nd play button then set true at 2nd position of your Boolean List and keep rest of false and notify your Adapter.
and your play pause button background is now based on Boolean List.

duplicate view instance issue with recycled/convertView row in listview

MyAdapter:
public class voice_player_listview_adapter extends ArrayAdapter<String> {
public ArrayList<String> Duration=null;
public ArrayList<String> voice_id=null;
private Activity context;
public voice_player_listview_adapter(Activity context,ArrayList<String> voice_id,ArrayList<String> Duration) {
super(context, R.layout.voice_player_listview,sender);
// TODO Auto-generated constructor stub
this.context=context;
this.voice_id=voice_id;
this.Duration=Duration;
}
public View getView(final int position, final View convertView, ViewGroup parent) {
View rowView=convertView;
final viewHolder holder; //viewHolder already created in some where
if (rowView==null)
{
LayoutInflater inflater = context.getLayoutInflater();
rowView = inflater.inflate(R.layout.voice_player_listview, parent, false);
holder= new viewHolder();
holder.icon=(ImageView) rowView.findViewById(R.id.download_play_icon);
holder.voice_duration=(TextView) rowView.findViewById(R.id.voiceDuration);
holder.voice_player_seekbar=(SeekBar) rowView.findViewById(R.id.voice_player_seekbar);
rowView.setTag(holder);
}
else
{
holder= (viewHolder) convertView.getTag();
}
holder.voice_duration.setText("00:"+this.Duration.get(position));
holder.icon.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
new voicePlayer(voice_id.get(position),holder);
}
});
...
VoicePlayer:
class voicePlayer {
MediaPlayer mediaPlayer;
SeekBar seekbar;
TextView voice_duration;
ImageView icon;
viewHolder rowView;
final Handler handler = new Handler();
public void getViews()
{
this.seekbar=rowView.voice_player_seekbar;
this.voice_duration=rowView.voice_duration;
this.icon=rowView.icon;
}
public voicePlayer(String voice_id,WavesAPI.viewHolder holder) {
this.rowView=holder;
getViews();
try {
mediaPlayer=new MediaPlayer();
FileInputStream fis = new FileInputStream(Environment.getExternalStorageDirectory()...);
mediaPlayer.setDataSource(fis.getFD());
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.prepare();
mediaPlayer.start();
this.icon.setImageResource(R.drawable.pause);
this.updateSeekbar();
this.seekbar_listener();
} catch (IOException e) {
}
} catch (IOException e) {
}
}
}
private void updateSeekbar()
{
final Runnable runnable = new Runnable() {
public void run() {
int position= // calculating the position of the mediaPlayer for updating the seekbar
seekbar.setProgress(position);
handler.postDelayed(this, 50);
voice_duration.setText("00:"+((WavesAPI.player_data.mediaPlayer.getDuration()/1000)-(WavesAPI.player_data.mediaPlayer.getCurrentPosition()/1000)));
}
};
handler.post(runnable);
}
public void seekbar_listener()
{
seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (fromUser)
{
int player_position=// calc new postion of the mediaPlayer
mediaPlayer.seekTo(player_position);
}
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
}
The problem: when i click on play icon on the row of listview the music plays and the seekbar gets updated correctly as long as i don't scroll. But, Since the screen/listview fit only 3 items, when i scroll down, every 4 row, i see the new row seekbar is updating with the same progress of the old row i played and scrolled off. i think the convertView generates the same old instance view that once created and passed to the voicePlayer. once i didn't consider convertView and for every getView i create new rowView by inflater.inflate , the duplicating instance issue was resolved but when i scroll off a item and re-scroll back to the item, updating was stopped.
The problem solved. i used ScrollView instead of ListView

Why Sound in MediaPlayer does not Play?

The problem is that the sound doesn't play.
When I run the application this sentence appear in (Android Mointor)" D/AbsListView: unregisterIRListener() is called "
the MainActivity.java code
public class MainActivity extends AppCompatActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayList<String> list = new ArrayList<String>();
list.add("item1");
//instantiate custom adapter
List adapter = new List(list, this);
//handle listview and assign adapter
ListView lView = (ListView)findViewById(R.id.listView);
lView.setAdapter(adapter);
}
}
the List.java code:
public class List extends BaseAdapter implements ListAdapter {
private ArrayList<String> list = new ArrayList<String>();
private Context context;
MediaPlayer mediaPlayer;
public List(ArrayList<String> list, Context context) {
this.list = list;
this.context = context;
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int pos) {
return list.get(pos);
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.activity_list, null);
}
//Handle TextView and display string from your list
TextView listItemText = (TextView)view.findViewById(R.id.list_item_string);
listItemText.setText(list.get(position));
//Handle buttons and add onClickListeners
Button addBtn = (Button)view.findViewById(R.id.add_btn);
addBtn.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
MediaPlayer.create(List.this.context, R.raw.people)
mediaPlayer.start();
notifyDataSetChanged();
}
});
return view;
}
}
I think you must be changed this to context
addBtn.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
mediaPlayer.create(context,R.raw.people);
mediaPlayer.start();
notifyDataSetChanged();
}
});
Try this:
#Override
public void onClick(View v) {
mediaPlayer = MediaPlayer.create(context,R.raw.people);
mediaPlayer.start();
notifyDataSetChanged();
}
You can use the below method to play a sound. It can be played from storage or url from Internet.
public void playAudio(String audioPath) {
try {
MediaPlayer mp = new MediaPlayer();
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.setDataSource(audioPath);
mp.prepare();
mp.start();
Log.d(TAG, "is playing audio...");
} catch (Exception e) {
Log.d(TAG, "cannot play audio: " + e.toString());
}
}

Changing specific ListView Image on boolean

I have a ListView with custom adapter with Image. I also have sound assigned to each item in ListView. I want when user for example click on 3rd item in ListView to change image of that item, and when user click on for example 15th item, to change item 3 image to old one, and change image of item 15 And so on. How can I do that?
This is my code:
Adapter:
#Override
public View getView(final int position, View convertView, ViewGroup parent){
View item=convertView;
HolderActivity holder=null;
if(item==null){
LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
item=inflater.inflate(R.layout.generator, parent,false);
holder=new HolderActivity(item);
item.setTag(holder);
}
else{
holder=(HolderActivity)item.getTag();
}
holder.transfer.setImageResource(transfer[position]);
holder.myImage.setImageResource(pictures[position]);
holder.ringName.setText(ringNames[position]);
holder.ringDesc.setText(descInfo[position]);
return item;
}
}
And then simple ItemClickListener in Main Activity
int[] songPos = { R.raw.position1, R.raw.position2, R.raw.position3,
R.raw.position4, R.raw.position4, R.raw.position5, R.raw.position6...etc etc
list.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View paramAnonymousView, int position, long id) {
CentralActivity.this.playSound(position);
}
});
private void playSound(int paramInt)
{
try
{
if ((CentralActivity.playing.booleanValue()) && (CentralActivity.position == paramInt))
{
Toast.makeText(CentralActivity.this, "It's Playing", Toast.LENGTH_SHORT).show();
}
else
{
CentralActivity.mp = MediaPlayer.create(CentralActivity.this, Integer.valueOf(this.songPos[paramInt]).intValue());
CentralActivity.mp.start();
CentralActivity.position = paramInt;
CentralActivity.playing = Boolean.valueOf(true);
CentralActivity.mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
{
public void onCompletion(MediaPlayer paramAnonymousMediaPlayer)
{
paramAnonymousMediaPlayer.release();
CentralActivity.playing = Boolean.valueOf(false);
}
});
}
}
catch (Exception localException) {}
}
Here are pieces for your code which should work:
Activity:
private ArrayAdapter mAdapter; // Make the mAdapter reachable by other methods
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
// If creating adapter from your activity, send it's context (this):
mAdapter = new ArrayAdapter(this,...);
...
}
private void playSound(int paramInt) {
try {
if ((CentralActivity.playing) && (CentralActivity.position == paramInt)) {
Toast.makeText(CentralActivity.this, "It's Playing", Toast.LENGTH_SHORT).show();
} else {
// Set activity variables
CentralActivity.position = paramInt;
CentralActivity.playing = true;
// Update ListView views
mAdapter.notifyDataSetChanged();
// Create MP and start playing
CentralActivity.mp = MediaPlayer.create(CentralActivity.this, Integer.valueOf(this.songPos[paramInt]).intValue());
CentralActivity.mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer paramAnonymousMediaPlayer) {
paramAnonymousMediaPlayer.release();
CentralActivity.playing = false;
// Update ListView views
mAdapter.notifyDataSetChanged();
}
});
CentralActivity.mp.start();
}
} catch (Exception localException) {
localException.printStackTrace();
}
}
Adapter:
public class CustomAdapter extends ArrayAdapter {
// Considering CentralActivity is the name of your Activity's class
private CentralActivity mActivity;
// Custom adapter's constructor
public CustomAdapter(Context context, ...) {
mActivity = (CentralActivity) context;
...
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View item = convertView;
HolderActivity holder = null;
if (item == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
item = inflater.inflate(R.layout.generator, parent, false);
holder = new HolderActivity(item);
item.setTag(holder);
} else {
holder = (HolderActivity) item.getTag();
}
if (mActivity.playing && mActivity.position == position) {
holder.myImage.setImageResource(pauseImageResource);
} else {
holder.myImage.setImageResource(pictures[position]);
}
holder.transfer.setImageResource(transfer[position]);
holder.ringName.setText(ringNames[position]);
holder.ringDesc.setText(descInfo[position]);
return item;
}
...
}
Note that you will obviously need to replace ... and maybe CentralActivity too, to corresponding equivalents in your code.
The idea is to keep track of which index is playing.
Create setter in your adapter class:
public void setPlayingIndex(int index){
mPlayingIndex = index;
if(mPlayingIndex != ListView.INVALID_POSITION){
notifyDataSetChanged();
}
}
Make sure you call this method when you play the sound, like:
mListAdapter.setPlayingIndex(index);
In your getView() method, besides the ViewHolder pattern code have this:
if(mPlayingIndex == position){
//add the playing image
}else{
// load normal
holder.transfer.setImageResource(transfer[position]);
holder.myImage.setImageResource(pictures[position]);
holder.ringName.setText(ringNames[position]);
holder.ringDesc.setText(descInfo[position]);
}

Multiple TextureViews in a listview render incorrect video

I am making an app where I have multiple texture views in a listview. I am using a list array adapter I always use so I know that I am properly recycling each list view item and that I am setting the correct url for the video in each texture view. However, If my list contains more than three videos, they start to "duplicate" themselves, meaning that the fourth list item renders, but video one renders in it instead of video four. Also, when I scroll down and back up, sometimes the video resource I have attacted to that texture view also changes like they are being "re-rendered" by the adapter. Should I not recycle the views? current relevant code:
public class VideoListAdapter extends ArrayAdapter<videoitem> {
Context context;
int phonewidth;
int videoPlaying =0;
List<MediaPlayer> playerList = new ArrayList();
int pos;
private final ImageDownloader mDownload = new ImageDownloader();
public VideoListAdapter(Context context, int resourceId, List<videoitem> items) {
super(context, resourceId, items);
this.context = context;
phonewidth = context.getResources().getDisplayMetrics().widthPixels;
}
private class ViewHolder {
RelativeLayout wrapper;
InlineVideoPlayer videoPoster;
TextView numberOfLikes;
TextView numberOfDislikes;
ImageView UserIcon;
TextView userName;
TextView created;
ProgressBar p;
LinearLayout l;
}
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
final videoitem rowItem = getItem(position);
pos = position;
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.videoitem,parent, false);
holder = new ViewHolder();
holder.wrapper = (RelativeLayout) convertView.findViewById(R.id.videoholder);
holder.l = (LinearLayout) convertView.findViewById(R.id.inlineVideoPlayer1);
// holder.videoPoster.setVideo("http//hub60.com/app/videos/" + rowItem.getVideo());
holder.UserIcon = (ImageView) convertView.findViewById(R.id.imageView1);
holder.numberOfDislikes = (TextView) convertView.findViewById(R.id.textView3);
holder.numberOfLikes = (TextView) convertView.findViewById(R.id.ratinglikes);
holder.created = (TextView) convertView.findViewById(R.id.textView2);
holder.userName = (TextView) convertView.findViewById(R.id.textView1);
holder.numberOfDislikes.setText(Integer.toString(position));
holder.numberOfLikes.setText(rowItem.getLikes());
holder.userName.setText(rowItem.getVideo());
holder.created.setText(rowItem.getCreated());
mDownload.download(rowItem.getIcon(), holder.UserIcon, null);
holder.l.getLayoutParams().height = phonewidth;
// vid.setLayoutParams(new LayoutParams(
// LayoutParams.MATCH_PARENT,
// LayoutParams.MATCH_PARENT));
convertView.setTag(holder);
} else{
holder = (ViewHolder) convertView.getTag();
holder.numberOfDislikes.setText(Integer.toString(position));
holder.numberOfLikes.setText(rowItem.getLikes());
holder.userName.setText(rowItem.getVideo());
holder.created.setText(rowItem.getCreated());
mDownload.download(rowItem.getIcon(), holder.UserIcon, null);
convertView.setId(position);
}
InlineVideoPlayer vid = new InlineVideoPlayer(rowItem.getVideo(),context);
((LinearLayout) holder.l).addView(vid);
return convertView;
}
in this particular case I took it out of the if/else deciding if the holder was empty and just added the view in question at the end. However I also had it in the if/else statement and am still experiencing the same behavior.
Custom texture view class
public class InlineVideoPlayer extends TextureView implements SurfaceTextureListener{
Context context;
MediaPlayer mp;
String url;
Surface surface;
SurfaceTexture s;
public InlineVideoPlayer(Context context, AttributeSet attrs)
{
super(context, attrs);
this.context = context;
}
public InlineVideoPlayer(String ur,Context context)
{
super(context);
this.setSurfaceTextureListener(this);
this.url = ur;
this.context = context;
// startVideo();
//Log.d("url",this.url);
}
#Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int arg1, int arg2) {
this.s = surface;
Log.d("url",this.url);
startVideo(surface);
}
#Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture arg0) {
return true;
}
#Override
public void onSurfaceTextureSizeChanged(SurfaceTexture arg0, int arg1,int arg2) {
}
#Override
public void onSurfaceTextureUpdated(SurfaceTexture arg0) {
}
public void setVideo(String url)
{
this.url = url;
}
public void startVideo(SurfaceTexture t)
{
this.surface = new Surface(t);
this.mp = new MediaPlayer();
this.mp.setSurface(this.surface);
try {
Uri uri = Uri.parse(this.url);
this.mp.setDataSource(this.context, uri);
this.mp.prepareAsync();
this.mp.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
mp.seekTo(2000);
mp.start();
// mp.pause();
}
});
} catch (IllegalArgumentException e1) {
e1.printStackTrace();
} catch (SecurityException e1) {
e1.printStackTrace();
} catch (IllegalStateException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
try {
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
}
try {
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
}
thank you in advance
the answer is: this is not possible, The developer must work with reusable cells and insert a movie player at the rightindex for the appropiate cell and when a cell is created null out the media player currently playing

Categories

Resources