【问题标题】:Android MediaController - Can't click on itemsAndroid MediaController - 无法点击项目
【发布时间】:2013-11-22 14:49:29
【问题描述】:

我有一个包含媒体文件链接的列表视图,它可以正常工作但没有媒体控制器,在应用媒体控制器后,我无法在媒体控制器出现期间从列表中选择另一个项目,我只能滚动列表视图,但我无法选择任何项目。如何在 Mediacontroller 出现期间使列表视图可选?

注意:当媒体控制器隐藏时它可以工作。

注意2:媒体控制器在播放媒体文件的过程中一直显示。

谢谢

[编辑]

这是我的布局代码,请看返回按钮(那个按钮是可点击的),但是项目列表不是...

.....
    <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>

.....

[编辑 2]

这是我的 onPrepared 函数

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();
    }
}

这也是我播放声音的功能......

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) {

            }
        }
    }

}

我希望这足以让你给我一些建议:)

【问题讨论】:

  • ListView 是否包含在与您传递给 setAnchorView 相同的 View 中?
  • @Dave :是的,Dave,我的 ListView 包含在我的播放器所在的同一个视图中。
  • 你能用用于创建和设置 MediaController 的代码更新问题吗? MediaController 将创建一个单独的窗口,我相信它会覆盖您的 ListView 而不是 Button。不过,我无法确定如何在没有看到代码的情况下修复它。
  • @Dave 是的,我会在几分钟内更新我的代码,这也是我的想法(也就是覆盖控件),但是当我把它放在另一个地方时,它们就不能再点击了......
  • @Mahuna 同样的问题。按返回键至少会隐藏控制器并允许选择列表中的项目。尚未弄清楚如何在控制器显示时允许单击列表项。

标签: android android-layout android-listview android-mediaplayer android-custom-view


【解决方案1】:

萨拉姆。不要将setOnItemClickListener 用于您的listView
而是使用Onclick 作为listView ROW 的父布局。
像这样:

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>

然后在您的活动中编写此方法

    public void playSelectedPodcast(View view){
    ViewHolder tag = (ViewHolder) view.getTag();
    mMediaController.show(5000);
    podcastIndex = tag.position;
    playPodcast(tag.position);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多