Package net.sf.pummel.model

Examples of net.sf.pummel.model.SongFile


  public void addFiles(File[] files) {
    if (files != null && files.length > 0) {

      AudioFile audioFile;
      Tag tag;
      SongFile songFile;
      List<Expression> list = new ArrayList<Expression>(2);
      list.add(ExpressionFactory.matchExp(SongFile.FILENAME_PROPERTY,
               new ExpressionParameter("filename")));
      list.add(ExpressionFactory.matchExp(SongFile.PATH_PROPERTY,
               new ExpressionParameter("path")));
      Expression andExpression = ExpressionFactory.joinExp(Expression.AND, list);
      SelectQuery query = new SelectQuery(SongFile.class, andExpression);
      query.setFetchLimit(1);
      Map<String, String> args = new HashMap<String, String>();
      for (File file : files) {
        args.put("filename", file.getName());
        args.put("path", file.getParent());
       
        System.out.println(file.getAbsolutePath());
       
        SelectQuery queryWithParameters = query.queryWithParameters(args);
        System.out.println(queryWithParameters.toString());
       
        List<?> existingSongFiles = context.performQuery(queryWithParameters);
        if (existingSongFiles.isEmpty()) {
          songFile = context.newObject(SongFile.class);
         
          songFile.setFilename(file.getName());
          songFile.setPath(file.getParent());

          songFiles.add(songFile);
        }
        else {
          songFile = (SongFile) existingSongFiles.get(0);
        }
       
        try {
          audioFile = AudioFileIO.read(file);
         
          AudioHeader header = audioFile.getAudioHeader();
         
          songFile.setTrackLength(header.getTrackLength());
          songFile.setBitRate(header.getBitRate());
          songFile.setEncoding(header.getEncodingType());
         
          tag = audioFile.getTag();
          if (tag != null) {
            List<TagField> artistFields = tag.getFields(FieldKey.ARTIST);
            for (TagField artistField : artistFields) {
View Full Code Here

TOP

Related Classes of net.sf.pummel.model.SongFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.