いくつかの画像とビデオをすべて生のフォルダーに保存しています。
ビデオは正常に再生されますが、画像を表示したい場合は次のようになります。
ビデオが発生する前に画像が最初に開始されたとしても
package com.example.tvrplayer;
import java.io.File;
import java.io.FileDescriptor;
import java.io.IOException;
import java.text.DateFormat.Field;
import java.util.ArrayList;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.widget.ImageView;
import android.widget.VideoView;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.WindowManager;
public class MainActivity extends Activity implements OnCompletionListener {
int playListIndex;
int currentMedia;
String mediaName;
ArrayList<Integer> playList = new ArrayList<Integer>();
private VideoView videoView;
private ImageView imageView;
Uri mediaPath;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
createPlayList();
currentMedia = 1;
try {
playMedia(this, currentMedia);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onCompletion(MediaPlayer mp) {
// play next video
currentMedia++;
if (currentMedia > playList.size() - 1) {
currentMedia = 0;
}
try {
playMedia(this, currentMedia);
} catch (IOException e) {
e.printStackTrace();
}
}
private void playMedia(Context context, int playListIndex) throws IOException {
int resourceID = playList.get(playListIndex); // This is the resource id
String path = "android.resource://" + getPackageName() + "/" + resourceID;
Uri uri = Uri.parse(path);
String filename = context.getResources().getResourceName(resourceID);
if (filename.contains("image")) {
imageView = (ImageView)findViewById(R.id.imageView);
imageView.setImageResource(resourceID);
} else if (filename.contains("video")) {
videoView = (VideoView) findViewById(R.id.videoView);
videoView.setVideoURI(uri);
videoView.start();
}
}
private void createPlayList() {
java.lang.reflect.Field[] fields = R.raw.class.getFields();
for(java.lang.reflect.Field f : fields)
try {
playList.add(f.getInt(null));
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) { }
java.lang.reflect.Field[] imagefields = R.drawable.class.getFields();
for(java.lang.reflect.Field f : imagefields)
try {
playList.add(f.getInt(null));
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) { }
}
}
これはコンソールに表示されるものです:
02-19 15:56:01.095: E/AlarmManagerService(190): android_server_AlarmManagerService_set to type=3, 614361.925000000
02-19 15:56:02.962: E/AlarmManagerService(190): android_server_AlarmManagerService_set to type=0, 1361290750.991000000
02-19 15:56:03.111: D/dalvikvm(931): GC_CONCURRENT freed 719K, 13% free 7177K/8199K, paused 5ms+2ms
02-19 15:56:03.705: D/dalvikvm(931): GC_CONCURRENT freed 31K, 9% free 7532K/8199K, paused 4ms+1ms
02-19 15:56:03.892: D/Finsky(931): [1] 5.onFinished: Installation state replication succeeded.
02-19 15:56:11.642: E/Watchdog(190): !@Sync 6562
02-19 15:56:12.377: E/AlarmManagerService(190): android_server_AlarmManagerService_set to type=2, 614812.728000000
02-19 15:56:12.384: I/GTalkService/c(451): [AndroidEndpoint@1093714392] connect: acct=1000001, state=CONNECTING
02-19 15:56:12.556: E/GTalkService(451): connectionClosed: no XMPPConnection - That's strange!
02-19 15:56:12.564: E/AlarmManagerService(190): android_server_AlarmManagerService_set to type=2, 614614.495000000
02-19 15:56:15.572: D/ConnectivityService(190): handleInetConditionHoldEnd: net=1, condition=0, published condition=0
02-19 15:56:15.572: D/STATUSBAR-NetworkController(272): onReceive() - CONNECTIVITY_ACTION, INET_CONDITION_ACTION
02-19 15:56:15.572: D/STATUSBAR-NotificationService(190): cancelNotification - pkg:com.android.systemui, id:273, tag:null
02-19 15:56:41.642: E/Watchdog(190): !@Sync 6563
02-19 15:56:59.994: E/AlarmManagerService(190): android_server_AlarmManagerService_set to type=3, 614363.041000000
02-19 15:57:00.002: D/KeyguardUpdateMonitor(190): received broadcast android.intent.action.TIME_TICK
02-19 15:57:00.009: D/KeyguardUpdateMonitor(190): handleTimeUpdate
02-19 15:57:00.009: D/STATUSBAR-Clock(272): onReceive() - ACTION_TIME_TICK
02-19 15:57:00.009: D/STATUSBAR-Clock(272): updateClock :15:57
02-19 15:57:00.033: D/STATUSBAR-Clock(272): onReceive() - ACTION_TIME_TICK
02-19 15:57:00.033: D/STATUSBAR-Clock(272): updateClock :15:57
02-19 15:57:01.111: E/AlarmManagerService(190): android_server_AlarmManagerService_set to type=3, 614421.926000000
02-19 15:57:11.642: E/Watchdog(190): !@Sync 6564
このアプリの目的のためのドローアブルではなく、生のフォルダーから画像を再生する必要があります。私は何か間違ったことをしていますか?