0

我在我的活动中使用媒体播放器和 mediaController 来播放音频。在我的活动中,我有一张与音频相关的图像,其下方是音频的描述。我希望 mediaController 从图像底部和描述上方显示。目前,即使我将图像作为锚视图,mediaController 也会出现在设备的底部。有没有办法可以将 mediaController 移到描述上方

4

1 回答 1

0

干得好:

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <VideoView
        android:id="@+id/videoview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/blue" />

</LinearLayout>

活动代码:

package com.appsopmaat.bethgazo;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.BinaryHttpResponseHandler;

public class Player extends Activity {

    VideoView videoView;
    MediaController mediaController;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.player);


        videoView = (VideoView) findViewById(R.id.videoview);
        mediaController = new MediaController(Player.this);
        videoView.setMediaController(mediaController);
                                videoView.setVideoURI(Uri.parse(mp3url));
                                videoView.start();
                            }
                        }
                    });
        }

        videoView.setOnErrorListener(new OnErrorListener() {

            @Override
            public boolean onError(MediaPlayer mp, int what, int extra) {
                // TODO Auto-generated method stub
                Toast.makeText(Player.this, "Error please try again.",
                        Toast.LENGTH_LONG).show();
                finish();
                return true;
            }
        });

        videoView.setOnPreparedListener(new OnPreparedListener() {

            @Override
            public void onPrepared(MediaPlayer mp) {
                // TODO Auto-generated method stub
                mediaController.show();
            }
        });

        videoView.setOnCompletionListener(new OnCompletionListener() {

            @Override
            public void onCompletion(MediaPlayer mp) {
                // TODO Auto-generated method stub
                finish();
            }
        });
    }
}
于 2013-04-18T08:16:04.373 回答