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
Asked
Active
Viewed 2,442 times
1 Answers
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();
}
});
}
}
-
Is it required to use a video view? I am not playing video – user2041902 Apr 18 '13 at 08:31
-
Well when you use a videoview you can set the background to the picture you want but since i dont think its possible to use the mediacontroller from xml i used a videoview. – Apr 18 '13 at 08:44
-
This still displays the mediaController at bottom of device – user2041902 Apr 18 '13 at 08:48
-
Sorry i didnt knew you wanted it above the description. maybe you can do like this:mediaController.setGravity(Gravity.CENTER); – Apr 18 '13 at 08:51
-
I don't think there is setGravity() for mediaController – user2041902 Apr 18 '13 at 08:59