0

I am using media player and mediaController in my activity to play audio. In my activity i have an image related to the audio and beneath it the description of the audio. I want the mediaController to be displayed from the bottom of the image and above the description. At present the mediaController appears at the bottom of the device even if i give the image as the anchor view. Is there a way I can move the mediaController above the description

user2041902
  • 593
  • 1
  • 6
  • 21

1 Answers1

0

Here you go:

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>

Activity Code:

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