我正在使用播放按钮进行imageview,如果用户点击播放按钮,则会在imageview内播放视频。有人可以帮忙解决这个问题吗?
由于
答案 0 :(得分:0)
我遇到了你想要制作具有静态图像并具有背景声音的播放器的问题
这是代码
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>
现在通过你的声音文件res / create“raw”目录/你的声音“foo.mp3”
和drawable中的图像文件/你的背景图片“bar.png”
现在这里的代码有3个按钮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; } }); } }
并且不要忘记改变 最终MediaPlayer mplayer = MediaPlayer.create(au.this,R.raw.robotrock);
R.raw。“你的声音文件名”
好吧,我认为这有助于你快乐:)