마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

동영상 플레이 리스트, 동영상파일 없을때 종료 되는 현상

0 추천

 

 

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
       // nPath = new String("/storage/extSdCard/Data/");
        nPath = new String("/storage/sdcard0/engdict/");
        PathList_prev = new ArrayList<String>();
        PathList_next = new ArrayList<String>();
        
        makeFileList();
    }
    
 public void onConfigurationChanged(Configuration newConfig) {
    	super.onConfigurationChanged(newConfig);
    	setContentView(R.layout.main);
    	
    	makeFileList();
    }



------------------------------------


public void updateFileList(String sPath) {
	    String ext = Environment.getExternalStorageState();
	    String path = null;
	    ListData temp;
	    int type;
	    long size = 0;
	    String name;
	    
	    if(sPath == null) {
		    if(ext.equals(Environment.MEDIA_MOUNTED)) {
		    	path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
		    } else {
		    	path = Environment.MEDIA_UNMOUNTED;
		    }
	    } else {
	    	path = sPath;
	    }
	    
	    dirText.setText(path);
	    nPath = path;
	
	    File files = new File(path);

		if(files.listFiles().length == 0)
		{
			path = "/storage/extSdCard/Data/"; // Ricky's test directory ;>
			 dirText.setText(path);
		    nPath = path;
			 files = new File(path);
			
		}
		
	    arrayList = new ArrayList<ListData>();
	    
	    if (files.listFiles().length == 0) {
	    	updateFileList(null);
	    	}

	    if(files.listFiles().length >= 0) {
		    for(File file : files.listFiles()) {
		    	name = file.getName();
		    	if(file.getName().endsWith(".mpg")
		    			||file.getName().endsWith(".avi")
		    			||file.getName().endsWith(".wmv")
		    			||file.getName().endsWith(".asf")
		    			||file.getName().endsWith(".mp4")
		    			||file.getName().endsWith(".mkv")
		    			||file.getName().endsWith(".m4v")
		    			||file.getName().endsWith(".3gp")) {
		    		type = 1;
				size = file.length();	
			    	temp = new ListData(type, name, size);
			    	arrayList.add(temp);				
		    	} 		    	
		    }
	    }
	    
	    adapter = new GroupAdapter(this,R.layout.listview,arrayList);
        fileList.setAdapter(adapter);       

    }
   
    private class GroupAdapter extends ArrayAdapter<Object> {
    	private ArrayList<ListData> item;
    	private ListData temp;
    	
    	@SuppressWarnings({ "unchecked", "rawtypes" })
		public GroupAdapter(Context ctx, int resourceID, ArrayList item) {
    		super(ctx, resourceID, item);
    		
    		this.item = item;
    	}
    	
    	public View getView(int position, View convertView, ViewGroup parent) {
    		View v = convertView;
    		if(v == null) {
    			LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    			v = vi.inflate(R.layout.listview, null);
    		}
    		temp = item.get(position);

    		Bitmap image =  ThumbnailUtils.createVideoThumbnail(nPath+temp.getname(), android.provider.MediaStore.Video.Thumbnails.MICRO_KIND);

    		if(temp == null){
    			
    		}
    		if(temp != null) {
    			ImageView icon = (ImageView)v.findViewById(R.id.imageView1);
    			TextView name = (TextView)v.findViewById(R.id.textView1);
    			TextView size = (TextView)v.findViewById(R.id.textView2);
    			switch(temp.gettype()) {
    			case 0:
    				icon.setImageResource(R.drawable.folder_horizontal);
    				break;
    			case 1:
    				icon.setImageBitmap(image);
    				break;
    			case 2:
    				icon.setImageResource(R.drawable.application_blue);
    				break;
    			default:
    				icon.setImageResource(R.drawable.document);
    				break;
    			}
    			name.setText(temp.getname());
    			if(temp.gettype() == 0) {
    				size.setText("(폴더)");
    			} else {
    				size.setText("(" + byteTranslater(temp.getsize()) + ")");
    			}
    		}
    		return v;
    	}
    }

8000이 max라 부분부분 넣었습니다.

main 에서는 EngDict 라는 폴더를 검색해서 동영상 파일을 읽어 드립니다. 

 

헌데 문제점은 Engdict 폴더를 읽을때 파일이 없으면 읽지를 못하고 종료 된다는 것입니다.

 

종료 처리를 해주려고 어러번 시도해보았으나 

잘 해결되지 않아 글을 쓰게 되었습니다.

 

고수님들에 조언이나 . 방법을 좀 알려주시면 저에게 많은 도움이 될듯 합니다.

 

감사합니다.

범어동머시마 (120 포인트) 님이 2013년 9월 13일 질문

1개의 답변

0 추천
파일을 읽기 전에 파일이 있는지 여부를 체크하시면 어떨까요?
아나콘다v (4,670 포인트) 님이 2013년 9월 13일 답변
...