Android媒体控制器定位

时间:2013-04-18 08:09:03

标签: android mediacontroller

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

1 个答案:

答案 0 :(得分: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();
            }
        });
    }
}