0

I have a list view that has links to media files, it works fine but without the mediacontroller, after applying a mediacontroller I'm not able to select another item from the list during the appearance of the mediacontroller, I can only scrolling the listview but I can't select any item. how can I make the list view selectable during the appearance of the Mediacontroller?

Note: It works while mediacontroller is hidden.

Note2: the media controller is shown all the time during the playing of the media file.

Thanks

[EDIT]

Here is my layout code, please see the return button (that button is clickable), but the list of items isn't...

.....
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:id="@+id/main_audio_player"
        android:orientation="horizontal"
        ></LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_marginTop="100dp"
        >
        <Button
            android:layout_width="150dp"
            android:layout_height="50dp"
            android:text="Return"
            android:id="@+id/btnReturn"
            android:clickable="true"
            android:layout_marginTop="10dp"

            >
        </Button>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
                <ListView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/lvPlaylist"
                    android:alpha="0.3">

                </ListView>
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

.....

[EDIT 2]

Here is my onPrepared function

public void onPrepared(MediaPlayer mediaPlayer) {

    try {

        mediaController.setMediaPlayer(this);

        mediaController.setAnchorView(findViewById(R.id.main_audio_player));

        handler.post(new Runnable() {

            public void run() {


                mediaController.setEnabled(true);
                mediaController.show();
            }

        });

    }
    catch (Exception mediaError)
    {
        Toast error = Toast.makeText(getApplicationContext(),"Media player error!",1000);
        error.show();
    }
}

and also here is my function for playing the sound...

public void PlayAudioFile(String filename){

    if(!emptyList){
        if(IsPlayed)
        {
            mediaPlayer.stop();
            mediaPlayer.release();
        }
        Integer fileIndex =0;
        if(filename != ""){
            fileIndex = myPlaylist.GetIndexByFilename(filename);
        }

        mediaPlayer = new MediaPlayer();
        if(myPlaylist.GetNumberOfItems()>0)
        {
            try {

                audioFile = myPlaylist.GetItemWithPathInPlaylistByPositionId(fileIndex);
                audioName = myPlaylist.GetItemInPlaylistByPositionId(fileIndex);
                ((TextView)findViewById(R.id.now_playing_text)).setText(audioName);

                mediaPlayer.setOnPreparedListener(this);

                mediaController = new MediaController(this);
            }
            catch (Exception errorPlayer){

            }
            try {
                mediaPlayer.setDataSource(audioFile);
                mediaPlayer.prepare();
                mediaPlayer.start();

                IsPlayed = true;
            } catch (IOException e) {

            }
        }
    }

}

I hope that is enough for you to give me some suggestions what to do :)

Mahuna
  • 21
  • 5
  • Is the ListView contained inside the same View as you pass to setAnchorView? – Dave Nov 24 '13 at 05:31
  • @Dave : Yes Dave, my ListView is contained inside the same view where my player is. – Mahuna Nov 25 '13 at 11:46
  • Can you update the question with the code used to create and set up the MediaController? The MediaController will create a separate Window, and I believe it is covering your ListView but not the Button. I can't be sure how to fix it without seeing code, though. – Dave Nov 25 '13 at 14:32
  • @Dave Yea I will update my code in few minutes, that was my idea too (that is covering the controls), but when I put it on another places they aren't clickable again... – Mahuna Nov 25 '13 at 15:51
  • @Mahuna Same issue. Pressing the back key will at least hide the controller and allow an item in the list to be selected. Haven't yet worked out how to allow a list item to be clicked while the controller is showing. – Spinner Jul 08 '14 at 15:49
  • Seems this is the issue: http://stackoverflow.com/questions/7909603/android-mediacontroller-intercepts-all-other-touch-events – Spinner Jul 08 '14 at 16:14

1 Answers1

1

Salam. Dont use setOnItemClickListener for your listView.
Instead use Onclick for your parent layout of your listView ROW.
like this:

list_row.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:onClick="playSelectedPodcast" > <!--- this is important-->
    <TextView 
        android:id="@+id/podcast_row_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:layout_gravity="right|center_vertical"
        />
</LinearLayout>

and then write this method in your activity

    public void playSelectedPodcast(View view){
    ViewHolder tag = (ViewHolder) view.getTag();
    mMediaController.show(5000);
    podcastIndex = tag.position;
    playPodcast(tag.position);
}
skrrgwasme
  • 9,358
  • 11
  • 54
  • 84
Mohammad
  • 68
  • 1
  • 12