I'm a newbie on android java programming with Eclipse (I have a .NET background) and fail to get a video played in an emulator (nor on an android htc desire)
My setup:
- Eclipse IDE for Java Developers, Version: Helios Service Release 2
- Android SDK and ADT Plugin for Eclipse
The video I'm using is a 3gp video I recorded with my htc desire.
I have tried the 2 approaches with
- VideoView
- SurfaceView with a MediaPlayer which I took out of the book from Reto Meier "Professional Android 2 Application Development".
I'm targetting Android 2.2 (both in the emulator, as well on my htc desire)
Details
1. VideoView approach
getDuration always returns -1 and even after calling videoView.start() isPlaying is false. Here's the code I'm using:
public class MyActivity extends Activity
{
private static final String FileName = "VIDEO0015.3gp";
private static final String MyTag = "MyActivity";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView videoView = (VideoView) findViewById(R.id.videoView1);
videoView.setKeepScreenOn(true);
File clip=new File(Environment.getExternalStorageDirectory(), FileName);
if (clip.exists())
{
videoView.setVideoPath(clip.getAbsolutePath());
int duration = videoView.getDuration();
if (videoView.canSeekForward())
{
videoView.seekTo(duration/2);
}
videoView.start();
}
}
}
The main.xml file:
<?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"
>
<VideoView android:id="@+id/videoView1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</VideoView>
</LinearLayout>
2. SurfaceView with MediaPlayer With this approach, I get the correct duration (about 15 sec) and isPlaying is true. Both nothing is to be seen and also video playing never is completed.
I will add the code if somebody wants to check it.
Thanks for any help, I'm getting desperate.
Frank