Я разрабатываю приложение, которое воспроизводит видео из плейлиста.Если на устройстве нет видео, приложение загружает его с сайта и переходит к следующему видео в списке.
На эмуляторе работает нормально, но на реальном устройстве возникает ошибка при вызове метода медиаплеера "onCompletion":
09-22 11:50:54.553: ERROR/AndroidRuntime(4529): FATAL EXCEPTION: main
09-22 11:50:54.553: ERROR/AndroidRuntime(4529): java.lang.NullPointerException
09-22 11:50:54.553: ERROR/AndroidRuntime(4529): at android.widget.VideoView$3.onCompletion(VideoView.java:347)
09-22 11:50:54.553: ERROR/AndroidRuntime(4529): at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:1304)
09-22 11:50:54.553: ERROR/AndroidRuntime(4529): at android.os.Handler.dispatchMessage(Handler.java:99)
09-22 11:50:54.553: ERROR/AndroidRuntime(4529): at android.os.Looper.loop(Looper.java:123)
09-22 11:50:54.553: ERROR/AndroidRuntime(4529): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-22 11:50:54.553: ERROR/AndroidRuntime(4529): at java.lang.reflect.Method.invokeNative(Native Method)
09-22 11:50:54.553: ERROR/AndroidRuntime(4529): at java.lang.reflect.Method.invoke(Method.java:521)
09-22 11:50:54.553: ERROR/AndroidRuntime(4529): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-22 11:50:54.553: ERROR/AndroidRuntime(4529): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-22 11:50:54.553: ERROR/AndroidRuntime(4529): at dalvik.system.NativeStart.main(Native Method)
Итак, приложение запускается и воспроизводит 1-е видео, то вылетает.PS устройство - dreambook w7
Может кто-нибудь помочь, пожалуйста?
вот код:
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
setContentView(R.layout.main);
FLcurrentVideo = 0;
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000L, 0, this);
boolean isGPS = locationManager.isProviderEnabled (LocationManager.GPS_PROVIDER);
if (isGPS == false) startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
//
//Downloading Play List here
//
File clip=new File(Environment.getExternalStorageDirectory(),
playList[FLcurrentVideo].substring(2, playList[FLcurrentVideo].length()-1)+".mp4");
if (FLReady[FLcurrentVideo]==1) {
video=(VideoView)findViewById(R.id.video);
video.setVideoPath(clip.getAbsolutePath());
video.requestFocus();
video.start();
}
else {
if (FLReady[FLcurrentVideo] == 0) {
new CheckOutVideos(false).execute(FLcurrentVideo);
}
}
video.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer player) {
if (FLstoppedVideo==1) {
FLstoppedVideo=2;
}
else if (FLstoppedVideo==2) {
FLstoppedVideo = 0;
File clip=new File(Environment.getExternalStorageDirectory(),
playList[stoppedVideoMarker].substring(2, playList[stoppedVideoMarker].length()-1)+".mp4");
video=(VideoView)findViewById(R.id.video);
video.setVideoPath(clip.getAbsolutePath());
video.requestFocus();
video.start();
video.seekTo(stoppedVideoTime);
video.resume();
}
else if (FLstoppedVideo==0) {
isGPSplaying = false;
int FL = 1;
while (FL == 1) {
if (FLcurrentVideo<count-1) FLcurrentVideo++;
else FLcurrentVideo = 0;
File clip=new File(Environment.getExternalStorageDirectory(),
playList[FLcurrentVideo].substring(2, playList[FLcurrentVideo].length()-1)+".mp4");
if (FLReady[FLcurrentVideo]==1) {
FL=0;
video=(VideoView)findViewById(R.id.video);
video.setVideoPath(clip.getAbsolutePath());
video.requestFocus();
video.start();
}
else {
FL = 1;
if (FLReady[FLcurrentVideo] == 0) {
new CheckOutVideos(false).execute(FLcurrentVideo);
}
}
}
}
}
});
Конец той же проблемы: изменение размера видео отлично работает на эмуляторено на реальном устройстве размер видео не изменился, но текст и изображения отображаются в «правильном» положении, над видео, размер которого не изменился.Вот main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_width="fill_parent">
<VideoView
android:id="@+id/video"
android:layout_width="600dip" android:layout_height="match_parent">
</VideoView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_width="180dip">
<TextView
android:id="@+id/clock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="time"
>
</TextView>
<TextView
android:id="@+id/location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="time"
>
</TextView>
<ImageView
android:id="@+id/image1"
android:layout_height="match_parent" android:layout_width="match_parent">
</ImageView>
</LinearLayout>
Заранее спасибо.
SentineL