正如你所看到的那样,在这个播放器中我想创建一个数组,它可以从设备内部存储器中的本地存储文本文件中获取视频路径列表。正如你在下面的代码中看到我正在使用的.add
将路径存储在数组中。请告诉我一个代码来读取文本文件并将其放入名为videoList
的数组中。提前感谢
public class AttractLoopMain extends Activity implements OnCompletionListener,
SurfaceHolder.Callback {
private MediaPlayer mediaPlayer;
private ArrayList<String> videoList = new ArrayList<String>();
private SurfaceHolder holder;
private int currentVideo = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.attract_loop);
//videoList.add("/mnt/sdcard/a1.mp4");
//videoList.add("/mnt/sdcard/a2.mp4");
//videoList.add("/sdcard/download/test9-3.m4v");
SurfaceView surface = (SurfaceView) findViewById(R.id.surface);
holder = surface.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
currentVideo = 0;
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
mediaPlayer.stop();
mediaPlayer.release();
finish();
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
}
答案 0 :(得分:0)
使用此代码
Scanner s = new Scanner(new File("filepath"));
ArrayList<String> list = new ArrayList<String>();
while (s.hasNext()){
list.add(s.next());
}
s.close();