Package org.jaudiotagger.tag.mp4.atom

Examples of org.jaudiotagger.tag.mp4.atom.Mp4NameBox


    public void parse( File file ) throws IOException {

        try {
            AudioFile f = AudioFileIO.read(file);
            Mp4Tag mp4tag = (Mp4Tag) f.getTag();

            this.artistTitle = mp4tag.getFirst(Mp4FieldKey.ARTIST);
            this.albumTitle = mp4tag.getFirst(Mp4FieldKey.ALBUM);
            this.albumArtist = mp4tag.getFirst(Mp4FieldKey.ALBUM_ARTIST);
            this.trackTitle = mp4tag.getFirst(FieldKey.TITLE);
            this.genre = mp4tag.getFirst(FieldKey.GENRE);
            this.trackNumber = ((Mp4TrackField) mp4tag.getFirstField(Mp4FieldKey.TRACK)).getTrackNo();
           
        } catch ( Exception e) {
            throw new IOException("Unable to read file: " + file.getName(), e);
        }
    }
View Full Code Here


        return (ext.equalsIgnoreCase("mp4") || ext.equalsIgnoreCase("m4a"));
    }

    @Override
    protected void copySpecificTagFields(Tag tag, Track track) {
        Mp4Tag mp4Tag = (Mp4Tag) tag;
        TrackData trackData = track.getTrackData();

        Mp4TrackField trackField = (Mp4TrackField) mp4Tag.getFirstField(Mp4FieldKey.TRACK);
        if (trackField != null) {
            if (trackField.getTrackNo() != null) {
                trackData.addTrack(trackField.getTrackNo().intValue());
            }
            if (trackField.getTrackTotal() != null) {
                trackData.addTrackTotal(trackField.getTrackTotal().intValue());
            }
        }

        Mp4DiscNoField discField = (Mp4DiscNoField) mp4Tag.getFirstField(Mp4FieldKey.DISCNUMBER);
        if (discField != null) {
            if (discField.getDiscNo() != null) {
                trackData.addDisc(discField.getDiscNo().intValue());
            }
            if (discField.getDiscTotal() != null) {
                trackData.addDiscTotal(discField.getDiscTotal().intValue());
            }
        }

        List<TagField> genreFields = new ArrayList<TagField>();
        genreFields.addAll(mp4Tag.get(Mp4FieldKey.GENRE_CUSTOM));
        genreFields.addAll(mp4Tag.get(Mp4FieldKey.GENRE_ITUNES));
        for (TagField genreField : genreFields) {
            trackData.addGenre(genreField.toString());
        }
    }
View Full Code Here

    @Override
    public void write(Track track) throws TagWriteException {
        try {
            org.jaudiotagger.audio.AudioFile af1 = AudioFileIO.read(track.getTrackData().getFile());
            Tag abstractTag = af1.getTag();
            copyTagFields(abstractTag, new Mp4Tag(), track);
      // workaround since track/tracktotal and disc/disctotal share same field
            handleTrackDiscFields(abstractTag, track);
      // workaround since genre and genre custom field types used
            handleGenreFields(abstractTag, track);
            AudioFileIO.write(af1);
View Full Code Here

    }

    private void handleGenreFields(Tag tag, Track track) throws FieldDataInvalidException, KeyNotFoundException {
      FieldValues genres = track.getTrackData().getGenres();
      if (genres != null && !genres.isEmpty()) {
        Mp4Tag mp4Tag = (Mp4Tag) tag;
       
        mp4Tag.deleteField(Mp4FieldKey.GENRE);
        mp4Tag.deleteField(Mp4FieldKey.GENRE_CUSTOM);
       
      for (int i = 0; i < genres.size(); i++) {
        String genre = genres.get(i);
          if (!Util.isEmpty(genre)) {
            mp4Tag.addField(FieldKey.GENRE, genre);
          }
        }
      }
    }
View Full Code Here

     *
     * There are gaps between these boxes

     */
    public Mp4Tag read(RandomAccessFile raf) throws CannotReadException, IOException {
        Mp4Tag tag = new Mp4Tag();

        //Get to the facts everything we are interested in is within the moov box, so just load data from file
        //once so no more file I/O needed
        Mp4BoxHeader moovHeader = Mp4BoxHeader.seekWithinLevel(raf, Mp4NotMetaFieldKey.MOOV.getFieldName());
        if (moovHeader == null) {
View Full Code Here

        if (SupportedFileFormat.FLAC.getFilesuffix().equals(file.getName().substring(file.getName().lastIndexOf('.')))) {
            return new FlacTag(VorbisCommentTag.createNewTag(), new ArrayList<MetadataBlockDataPicture>());
        } else if (SupportedFileFormat.OGG.getFilesuffix().equals(file.getName().substring(file.getName().lastIndexOf('.')))) {
            return VorbisCommentTag.createNewTag();
        } else if (SupportedFileFormat.MP4.getFilesuffix().equals(file.getName().substring(file.getName().lastIndexOf('.')))) {
            return new Mp4Tag();
        } else if (SupportedFileFormat.M4A.getFilesuffix().equals(file.getName().substring(file.getName().lastIndexOf('.')))) {
            return new Mp4Tag();
        } else if (SupportedFileFormat.M4P.getFilesuffix().equals(file.getName().substring(file.getName().lastIndexOf('.')))) {
            return new Mp4Tag();
        } else if (SupportedFileFormat.WAV.getFilesuffix().equals(file.getName().substring(file.getName().lastIndexOf('.')))) {
            return new WavTag();
        } else {
            throw new RuntimeException("Unable to create default tag for this file format");
        }
View Full Code Here

     * @param raf
     * @param rafTemp
     * @throws IOException
     */
    public void delete(RandomAccessFile raf, RandomAccessFile rafTemp) throws IOException {
        Mp4Tag tag = new Mp4Tag();

        try {
            write(tag, raf, rafTemp);
        } catch (CannotWriteException cwe) {
            throw new IOException(cwe.getMessage());
View Full Code Here

    }

    protected void build(ByteBuffer data) throws UnsupportedEncodingException {
        //Data actually contains a 'Data' Box so process data using this
        Mp4BoxHeader header = new Mp4BoxHeader(data);
        Mp4DataBox databox = new Mp4DataBox(header, data);
        dataSize = header.getDataLength();
        content = databox.getContent();
    }
View Full Code Here


    protected void build(ByteBuffer data) throws UnsupportedEncodingException {
        //Data actually contains a 'Data' Box so process data using this
        Mp4BoxHeader header = new Mp4BoxHeader(data);
        Mp4DataBox databox = new Mp4DataBox(header, data);
        dataSize = header.getDataLength();
        numbers = databox.getNumbers();

        //Track number always hold three values, we can discard the first one, the second one is the track no
        //and the third is the total no of tracks so only use if not zero
        StringBuffer sb = new StringBuffer();
        if (numbers != null) {
View Full Code Here

    }

    protected void build(ByteBuffer data) throws UnsupportedEncodingException {
        //Data actually contains a 'Data' Box so process data using this
        Mp4BoxHeader header = new Mp4BoxHeader(data);
        Mp4DataBox databox = new Mp4DataBox(header, data);
        dataSize = header.getDataLength();
        content = databox.getContent();
        numbers = databox.getNumbers();
    }
View Full Code Here

TOP

Related Classes of org.jaudiotagger.tag.mp4.atom.Mp4NameBox

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.