⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 songinfodialog.java

📁 YOYOPlayer MP3播放器 java+JMF实现
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            .addComponent(jComboBox1, 0, 251, Short.MAX_VALUE)            .addGroup(jPanel2Layout.createSequentialGroup()                .addComponent(jLabel10)                .addContainerGap())            .addComponent(jComboBox2, 0, 251, Short.MAX_VALUE)        );        jPanel2Layout.setVerticalGroup(            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(jPanel2Layout.createSequentialGroup()                .addComponent(jLabel9)                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addComponent(jLabel10)                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)                .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                .addContainerGap())        );        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());        getContentPane().setLayout(layout);        layout.setHorizontalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(layout.createSequentialGroup()                .addContainerGap()                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)                    .addGroup(layout.createSequentialGroup()                        .addComponent(jLabel5)                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                        .addComponent(fileName, javax.swing.GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE))                    .addGroup(layout.createSequentialGroup()                        .addComponent(jButton1)                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                        .addComponent(jButton2)                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                        .addComponent(jButton3))                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))                .addContainerGap())        );        layout.setVerticalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(layout.createSequentialGroup()                .addContainerGap()                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                    .addComponent(jLabel5)                    .addComponent(fileName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                    .addComponent(jButton2)                    .addComponent(jButton3)                    .addComponent(jButton1))                .addContainerGap())        );        pack();    }// </editor-fold>//GEN-END:initComponents    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed        // TODO add your handling code here:        this.dispose();    }//GEN-LAST:event_jButton3ActionPerformed    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed        // TODO add your handling code here:        if (title.getText() == null || title.getText().trim().equals("")) {            JOptionPane.showMessageDialog(this, Config.getResource("title.empty"));            return;        }        doSave();        item.reRead();    }//GEN-LAST:event_jButton2ActionPerformed    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed        // TODO add your handling code here:        item.reRead();        init();    }//GEN-LAST:event_jButton1ActionPerformed    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed        // TODO add your handling code here:        int index = jComboBox1.getSelectedIndex();        Config.getConfig().setReadTagOrder(readOrder[index]);    }//GEN-LAST:event_jComboBox1ActionPerformed    private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox2ActionPerformed        // TODO add your handling code here:        int index = jComboBox2.getSelectedIndex();        Config.getConfig().setWriteTagMode(writeMode[index]);    }//GEN-LAST:event_jComboBox2ActionPerformed    private void doSave() {        log.log(Level.INFO,"调用了doSave");        //先不管,先把显示的标签改好再说,然后再决定是否写入文件        item.setArtist(artist.getText());        item.setAlbum(album.getText());        item.setComment(comment.getText());        item.setTitle(title.getText());        item.setYear(year.getText());        item.setGenre(genre.getText());        item.setTrack(track.getText());        item.refresh();        //如果这个项目是一个文件,则可以写入信息到它里面去        //否则就只能改本地了        if (item.isFile()) {            try {                //得到文件的类型,好决定以哪种方式写入标签                String type = item.getType();                if (type.equalsIgnoreCase("mp3")) {                    log.log(Level.INFO, "写入MP3标签");                    doSaveMP3();                } else if (type.equalsIgnoreCase("flac")) {                    log.log(Level.INFO, "写入FLAC格式标签");                    doSaveFlac();                } else if (type.equalsIgnoreCase("ogg")) {                    log.log(Level.INFO, "写入Ogg标签");                    doSaveOgg();                } else if (type.equalsIgnoreCase("ape")) {                    log.log(Level.INFO, "写入APE标签");                    doSaveApe();                } else {                    log.log(Level.INFO, "忽略,不写入任何标签");                //忽略,不写,免得写错了影响格式                }            } catch (Exception ex) {                Logger.getLogger(SongInfoDialog.class.getName()).log(Level.SEVERE, null, ex);                JOptionPane.showMessageDialog(this, ex.toString());            }        }        this.dispose();        Config.getConfig().getPlWindow().repaint();    }    private void doSaveApe() throws Exception {        APEv2Tag tag = new APEv2Tag();        tag.setAlbum(album.getText());        tag.setArtist(artist.getText());        tag.setComment(comment.getText());        tag.setGenre(genre.getText());        tag.setTitle(title.getText());        tag.setTrack(track.getText());        tag.setYear(year.getText());        RandomAccessFile raf = new RandomAccessFile(item.getLocation(), "rw");        try {            tag.write(raf, false);        } finally {            if (raf != null) {                raf.close();            }        }    }    private void doSaveFlac() throws Exception {        RandomAccessFile raf = null, temp = null;        File f = null;        try {            raf = new RandomAccessFile(item.getLocation(), "rw");            f = File.createTempFile("yoyo", "tmp");            temp = new RandomAccessFile(f, "rw");            FlacTagWriter w = new FlacTagWriter();            VorbisCommentTag vt = new VorbisCommentTag();            vt.setAlbum(album.getText());            vt.setArtist(artist.getText());            vt.setComment(comment.getText());            vt.setGenre(genre.getText());            vt.setTitle(title.getText());            vt.setTrack(track.getText());            vt.setYear(year.getText());            vt.setVendor("hadeslee");            FlacTag tag = new FlacTag(vt, new ArrayList<MetadataBlockDataPicture>());            w.write(tag, raf, temp);        } finally {            if (raf != null) {                raf.close();            }            if (temp != null) {                temp.close();            }            if (f != null) {                f.delete();            }        }    }    private void doSaveOgg() throws Exception {        RandomAccessFile raf = null, temp = null;        File f = null;        try {            raf = new RandomAccessFile(item.getLocation(), "rw");            f = File.createTempFile("temp", "fix");            log.log(Level.INFO, "临时文件是:" + f.getPath());            temp = new RandomAccessFile(f, "rw");            OggVorbisTagWriter w = new OggVorbisTagWriter();            VorbisCommentTag vt = new VorbisCommentTag();            vt.setAlbum(album.getText());            vt.setArtist(artist.getText());            vt.setComment(comment.getText());            vt.setGenre(genre.getText());            vt.setTitle(title.getText());            vt.setTrack(track.getText());            vt.setYear(year.getText());            vt.setVendor("hadeslee");            w.write(vt, raf, temp);            temp.seek(0);            raf.setLength(temp.length());            raf.seek(0);            raf.getChannel().transferFrom(temp.getChannel(), 0, temp.length());            log.log(Level.INFO, "完毕");        } finally {            if (raf != null) {                raf.close();            }            if (temp != null) {                temp.close();            }            if (f != null) {                f.delete();            }        }    }    private void doSaveMP3() throws Exception {        MP3File mp3 = new MP3File(new File(item.getLocation()), 0);        int mode = Config.getConfig().getWriteTagMode();        String encoding = Config.getConfig().getEncoding();        if ((mode & Config.WRITEMODE_APEv2) == Config.WRITEMODE_APEv2) {            APEv2Tag tag = new APEv2Tag();            tag.setAlbum(album.getText());            tag.setArtist(artist.getText());            tag.setComment(comment.getText());            tag.setGenre(genre.getText());            tag.setTitle(title.getText());            tag.setTrack(track.getText());            tag.setYear(year.getText());            mp3.setAPEv2Tag(tag);            log.log(Level.INFO,"写出APEv2标签");        }        if ((mode & Config.WRITEMODE_ID3v1) == Config.WRITEMODE_ID3v1) {            ID3v1Tag tag = new ID3v1Tag();            tag.setAlbum(Util.convertString(album.getText(), encoding, "ISO8859-1"));            tag.setArtist(Util.convertString(artist.getText(), encoding, "ISO8859-1"));            tag.setComment(Util.convertString(comment.getText(), encoding, "ISO8859-1"));            tag.setGenre(Util.convertString(genre.getText(), encoding, "ISO8859-1"));            tag.setTitle(Util.convertString(title.getText(), encoding, "ISO8859-1"));            tag.setYear(Util.convertString(year.getText(), encoding, "ISO8859-1"));            mp3.setID3v1Tag(tag);            log.log(Level.INFO,"写出ID3v1标签");        }        if ((mode & Config.WRITEMODE_ID3v2) == Config.WRITEMODE_ID3v2) {            //这里写出的是最新的ID3V24标签,可能有些播放器会不认识            ID3v24Tag tag = new ID3v24Tag();            tag.setAlbum(Util.convertString(album.getText(), encoding, "ISO8859-1"));            tag.setArtist(Util.convertString(artist.getText(), encoding, "ISO8859-1"));            tag.setComment(Util.convertString(comment.getText(), encoding, "ISO8859-1"));            tag.setGenre(Util.convertString(genre.getText(), encoding, "ISO8859-1"));            tag.setTitle(Util.convertString(title.getText(), encoding, "ISO8859-1"));            tag.setTrack(Util.convertString(track.getText(), encoding, "ISO8859-1"));            tag.setYear(Util.convertString(year.getText(), encoding, "ISO8859-1"));            mp3.setID3v2TagOnly(tag);            log.log(Level.INFO,"写出ID3v2标签");        }        mp3.save();    }    // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.JTextField album;    private javax.swing.JTextField artist;    private javax.swing.JTextArea comment;    private javax.swing.JTextField fileName;    private javax.swing.JTextField genre;    private javax.swing.JButton jButton1;    private javax.swing.JButton jButton2;    private javax.swing.JButton jButton3;    private javax.swing.JComboBox jComboBox1;    private javax.swing.JComboBox jComboBox2;    private javax.swing.JLabel jLabel1;    private javax.swing.JLabel jLabel10;    private javax.swing.JLabel jLabel2;    private javax.swing.JLabel jLabel3;    private javax.swing.JLabel jLabel4;    private javax.swing.JLabel jLabel5;    private javax.swing.JLabel jLabel6;    private javax.swing.JLabel jLabel7;    private javax.swing.JLabel jLabel8;    private javax.swing.JLabel jLabel9;    private javax.swing.JPanel jPanel1;    private javax.swing.JPanel jPanel2;    private javax.swing.JScrollPane jScrollPane1;    private javax.swing.JTextField title;    private javax.swing.JTextField track;    private javax.swing.JTextField year;    // End of variables declaration//GEN-END:variables}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -