开发者

How to play video in inside of image view in android

I am putting imageview with play开发者_JAVA百科 button, if user click the play button, then videoview will be played inside the imageview. can anybody help in this problem please with some sample ?

Thanks


Mohan

I got your problem you want to make a player which has static image and has background sound

here is the code

Main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/image"
>
<Button android:id="@+id/play"  
        android:layout_width="100px"
        android:layout_height="wrap_content"
        android:text="Play" />

<Button android:id="@+id/pause"
        android:layout_width="100px"
        android:layout_height="wrap_content"
        android:text="Pause" />

<Button android:id="@+id/stop"      
        android:layout_width="100px"
        android:layout_height="wrap_content"
        android:text="Stop" />

<Button android:id="@+id/info"          
        android:layout_width="100px"
        android:layout_height="wrap_content"
        android:text="Info" />

</LinearLayout>

now past your sound file in res/create "raw" directory/ your sound "foo.mp3"

and image file in drawable/your background image "bar.png"

now here is the code has 3 button PLAY PUSH STOP ...

package cm.ex.au;


import java.io.IOException;

import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class au extends Activity
{
/** Called when the activity is first created. */
protected static final int PLAY = 0x101;
protected static final int STOP = 0x102;
protected static final int PAUSE = 0x103;
int State;

public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);

final MediaPlayer mplayer = MediaPlayer.create(au.this,R.raw.robotrock);
mplayer.stop();

// PLAY button
Button play = (Button) this.findViewById(R.id.play);
State = STOP;
play.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {

// mp.prepare();
//mplayer.reset();
if (State == STOP)
{
try
{
mplayer.prepare();
}
catch(IOException e)
{
Log.d("AudioPlayer","IOException");
}
}
mplayer.start();
State = PLAY;
mplayer.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer arg0) {
// End of file
}
});
}
});

// PAUSE button
Button pause = (Button) this.findViewById(R.id.pause);


pause.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
mplayer.pause();
State = PAUSE;
}
});

// STOP button
Button stop = (Button) this.findViewById(R.id.stop);
stop.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
mplayer.stop();
State = STOP;
}
});

}
}

and do not forget to change final MediaPlayer mplayer = MediaPlayer.create(au.this,R.raw.robotrock);

R.raw."your sound file name "

ok i think it is help you n joy :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜