Video Player with SDK 0.9

All your problems with Audio, Video and Images.

Video Player with SDK 0.9

Postby amicpp » Sat Nov 15, 2008 1:24 am

Hallo ervery Body ,i want to play Video from the SDCARD ,and i just use this Code with SDK 0.9 ,but it dosn't work ,the Applikation was succesfuly installed !!!????????? kann any Body help me plaese ? may be there is some thing to do with the OnPrepared() Method ????? hier is the Code :::

package com.Android.Video2;

import java.io.IOException;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.ImageButton;

public class Video2 extends Activity implements SurfaceHolder.Callback {
private static final String TAG = "VideoPlayer";

private MediaPlayer mp;
private SurfaceView mPreview;
private SurfaceHolder holder;
private ImageButton mPlay;
private ImageButton mPause;
private ImageButton mReset;
private ImageButton mStop;

//private String path = "/sdcard/video.3gp";

/**
* Called when the activity is first created.
*/
public void onCreate(Bundle icicle) {
super.onCreate(icicle);

setContentView(R.layout.main);

// stellen die Buttons play/pause/reset/stop ein
mPreview = (SurfaceView) findViewById(R.id.surface);
mPlay = (ImageButton) findViewById(R.id.play);
mPause = (ImageButton) findViewById(R.id.pause);
mReset = (ImageButton) findViewById(R.id.reset);
mStop = (ImageButton) findViewById(R.id.stop);

mPlay.setOnClickListener(new View.OnClickListener() {
MediaPlayer mp = new MediaPlayer();
public void onClick(View view) {

try {
mp.setDataSource( "/sdcard/video.3gp" );
}catch (IOException e){
// TODO Auto-generated catch block
e.printStackTrace();
}

mp.start();
}
}
);
mPause.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (mp != null) {
mp.pause();
}
}
});
mReset.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (mp != null) {
mp.seekTo(0);
}
}
});
mStop.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (mp != null) {
mp.stop();
mp.release();
}
}
});

// seten der transparency
//getWindow().setFormat(PixelFormat.UNKNOWN);


// Set a size for the video screen
holder = mPreview.getHolder();
holder.addCallback(this);
holder.setFixedSize(400,300);

}

// Einstellen der Screen von der video output
// mp.setDisplay((SurfaceHolder) mPreview.getHolder().getSurface());


//}

public void surfaceCreated(SurfaceHolder surfaceholder) {
Log.d(TAG, "surfaceCreated called");
//return true;
}

public void surfaceChanged(SurfaceHolder surfaceholder, int i, int j, int k) {
Log.d(TAG, "surfaceChanged called");
}

public void surfaceDestroyed(SurfaceHolder surfaceholder) {
Log.d(TAG, "surfaceDestroyed called");
}

//**************************
public void onPrepared(MediaPlayer mediaplayer) {
Log.d(TAG, "onPrepared called");
}
}

////////////// and The XML :::
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<SurfaceView android:id="@+id/surface"
android:layout_width="300px"
android:layout_height="250px">
</SurfaceView>

<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:padding="10dip">

<ImageButton android:id="@+id/play"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/play"/>

<ImageButton android:id="@+id/pause"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/pause"/>

<ImageButton android:id="@+id/reset"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/reset"/>

<ImageButton android:id="@+id/stop"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/stop"/>

</LinearLayout>
</LinearLayout>

thanks
amicpp
Freshman
Freshman
 
Posts: 3
Joined: Wed Nov 05, 2008 4:00 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 28 guests