本文整理汇总了Java中org.jaudiotagger.audio.AudioFile.getAudioHeader方法的典型用法代码示例。如果您正苦于以下问题:Java AudioFile.getAudioHeader方法的具体用法?Java AudioFile.getAudioHeader怎么用?Java AudioFile.getAudioHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jaudiotagger.audio.AudioFile
的用法示例。
在下文中一共展示了AudioFile.getAudioHeader方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAudioTrackLength
import org.jaudiotagger.audio.AudioFile; //导入方法依赖的package包/类
public int getAudioTrackLength(URL url) {
try {
// 只能获得本地歌曲文件的信息
AudioFile file = AudioFileIO.read(new File(url.toURI()));
// 获取音频文件的头信息
AudioHeader audioHeader = file.getAudioHeader();
// 文件长度 转换成时间
return audioHeader.getTrackLength();
} catch (CannotReadException | IOException | TagException
| ReadOnlyFileException | InvalidAudioFrameException
| URISyntaxException e) {
e.printStackTrace();
return -1;
}
}
示例2: buildMedia
import org.jaudiotagger.audio.AudioFile; //导入方法依赖的package包/类
@Override
protected Media buildMedia(final MediaUploadBatch context) throws MediaReaderException, IOException {
final String fileName = getFile().getAbsolutePath();
try {
final AudioFile audioFile = AudioFileIO.read(getFile());
final Tag tag = audioFile.getTag();
final AudioHeader header = audioFile.getAudioHeader();
final byte[] thumbnail;
final List<Artwork> artwork = tag.getArtworkList();
if (artwork.isEmpty()) {
thumbnail = new byte[0];
} else {
thumbnail = artwork.get(0).getBinaryData();
}
final Map<String, Object> metadata = new HashMap<>(2);
metadata.put("Tags", copyTags(tag));
metadata.put("Headers", copyHeaders(header));
return new Media(getFile(), fileName, context.getTemplate(), metadata, thumbnail);
} catch (final CannotReadException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) {
throw new MediaReaderException(e);
}
}
示例3: getRawMetaData
import org.jaudiotagger.audio.AudioFile; //导入方法依赖的package包/类
/**
* Parses meta data for the given music file. No guessing or reformatting is done.
*
*
* @param file The music file to parse.
* @return Meta data for the file.
*/
@Override
public MetaData getRawMetaData(File file) {
MetaData metaData = new MetaData();
try {
AudioFile audioFile = AudioFileIO.read(file);
Tag tag = audioFile.getTag();
if (tag != null) {
metaData.setAlbumName(getTagField(tag, FieldKey.ALBUM));
metaData.setTitle(getTagField(tag, FieldKey.TITLE));
metaData.setYear(parseYear(getTagField(tag, FieldKey.YEAR)));
metaData.setGenre(mapGenre(getTagField(tag, FieldKey.GENRE)));
metaData.setDiscNumber(parseInteger(getTagField(tag, FieldKey.DISC_NO)));
metaData.setTrackNumber(parseTrackNumber(getTagField(tag, FieldKey.TRACK)));
String songArtist = getTagField(tag, FieldKey.ARTIST);
String albumArtist = getTagField(tag, FieldKey.ALBUM_ARTIST);
metaData.setArtist(StringUtils.isBlank(songArtist) ? albumArtist : songArtist);
metaData.setAlbumArtist(StringUtils.isBlank(albumArtist) ? songArtist : albumArtist);
}
AudioHeader audioHeader = audioFile.getAudioHeader();
if (audioHeader != null) {
metaData.setVariableBitRate(audioHeader.isVariableBitRate());
metaData.setBitRate((int) audioHeader.getBitRateAsNumber());
metaData.setDurationSeconds(audioHeader.getTrackLength());
}
} catch (Throwable x) {
LOG.warn("Error when parsing tags in " + file, x);
}
return metaData;
}
示例4: getMetadata
import org.jaudiotagger.audio.AudioFile; //导入方法依赖的package包/类
public Metadata getMetadata(File file) throws IOException, TagException, ReadOnlyFileException, InvalidAudioFrameException, MetadataException {
try{
AudioFile audioFile = audioFileHelper.read(file);
tag = (Mp4Tag) audioFile.getTag();
header = audioFile.getAudioHeader();
return generateMetadata(file);
} catch (CannotReadException cnr){
return null;
}
}
示例5: onCreateDialog
import org.jaudiotagger.audio.AudioFile; //导入方法依赖的package包/类
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Activity context = getActivity();
final Song song = getArguments().getParcelable("song");
MaterialDialog dialog = new MaterialDialog.Builder(context)
.customView(R.layout.dialog_file_details, true)
.title(context.getResources().getString(R.string.label_details))
.positiveText(android.R.string.ok)
.build();
View dialogView = dialog.getCustomView();
final TextView fileName = (TextView) dialogView.findViewById(R.id.file_name);
final TextView filePath = (TextView) dialogView.findViewById(R.id.file_path);
final TextView fileSize = (TextView) dialogView.findViewById(R.id.file_size);
final TextView fileFormat = (TextView) dialogView.findViewById(R.id.file_format);
final TextView trackLength = (TextView) dialogView.findViewById(R.id.track_length);
final TextView bitRate = (TextView) dialogView.findViewById(R.id.bitrate);
final TextView samplingRate = (TextView) dialogView.findViewById(R.id.sampling_rate);
fileName.setText(makeTextWithTitle(context, R.string.label_file_name, "-"));
filePath.setText(makeTextWithTitle(context, R.string.label_file_path, "-"));
fileSize.setText(makeTextWithTitle(context, R.string.label_file_size, "-"));
fileFormat.setText(makeTextWithTitle(context, R.string.label_file_format, "-"));
trackLength.setText(makeTextWithTitle(context, R.string.label_track_length, "-"));
bitRate.setText(makeTextWithTitle(context, R.string.label_bit_rate, "-"));
samplingRate.setText(makeTextWithTitle(context, R.string.label_sampling_rate, "-"));
try {
if (song != null) {
final File songFile = new File(song.data);
if (songFile.exists()) {
AudioFile audioFile = AudioFileIO.read(songFile);
AudioHeader audioHeader = audioFile.getAudioHeader();
fileName.setText(makeTextWithTitle(context, R.string.label_file_name, songFile.getName()));
filePath.setText(makeTextWithTitle(context, R.string.label_file_path, songFile.getAbsolutePath()));
fileSize.setText(makeTextWithTitle(context, R.string.label_file_size, getFileSizeString(songFile.length())));
fileFormat.setText(makeTextWithTitle(context, R.string.label_file_format, audioHeader.getFormat()));
trackLength.setText(makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString(audioHeader.getTrackLength() * 1000)));
bitRate.setText(makeTextWithTitle(context, R.string.label_bit_rate, audioHeader.getBitRate() + " kb/s"));
samplingRate.setText(makeTextWithTitle(context, R.string.label_sampling_rate, audioHeader.getSampleRate() + " Hz"));
}
}
} catch (@NonNull CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) {
Log.e(TAG, "error while reading the song file", e);
}
return dialog;
}
示例6: onCreateDialog
import org.jaudiotagger.audio.AudioFile; //导入方法依赖的package包/类
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Activity context = getActivity();
final Song song = getArguments().getParcelable("song");
MaterialDialog dialog = new MaterialDialog.Builder(context)
.customView(R.layout.dialog_file_details, true)
.title(context.getResources().getString(R.string.label_details))
.positiveText(android.R.string.ok)
.build();
View dialogView = dialog.getCustomView();
final TextView fileName = dialogView.findViewById(R.id.file_name);
final TextView filePath = dialogView.findViewById(R.id.file_path);
final TextView fileSize = dialogView.findViewById(R.id.file_size);
final TextView fileFormat = dialogView.findViewById(R.id.file_format);
final TextView trackLength = dialogView.findViewById(R.id.track_length);
final TextView bitRate = dialogView.findViewById(R.id.bitrate);
final TextView samplingRate = dialogView.findViewById(R.id.sampling_rate);
fileName.setText(makeTextWithTitle(context, R.string.label_file_name, "-"));
filePath.setText(makeTextWithTitle(context, R.string.label_file_path, "-"));
fileSize.setText(makeTextWithTitle(context, R.string.label_file_size, "-"));
fileFormat.setText(makeTextWithTitle(context, R.string.label_file_format, "-"));
trackLength.setText(makeTextWithTitle(context, R.string.label_track_length, "-"));
bitRate.setText(makeTextWithTitle(context, R.string.label_bit_rate, "-"));
samplingRate.setText(makeTextWithTitle(context, R.string.label_sampling_rate, "-"));
try {
if (song != null) {
final File songFile = new File(song.data);
if (songFile.exists()) {
AudioFile audioFile = AudioFileIO.read(songFile);
AudioHeader audioHeader = audioFile.getAudioHeader();
fileName.setText(makeTextWithTitle(context, R.string.label_file_name, songFile.getName()));
filePath.setText(makeTextWithTitle(context, R.string.label_file_path, songFile.getAbsolutePath()));
fileSize.setText(makeTextWithTitle(context, R.string.label_file_size, getFileSizeString(songFile.length())));
fileFormat.setText(makeTextWithTitle(context, R.string.label_file_format, audioHeader.getFormat()));
trackLength.setText(makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString(audioHeader.getTrackLength() * 1000)));
bitRate.setText(makeTextWithTitle(context, R.string.label_bit_rate, audioHeader.getBitRate() + " kb/s"));
samplingRate.setText(makeTextWithTitle(context, R.string.label_sampling_rate, audioHeader.getSampleRate() + " Hz"));
}
}
} catch (@NonNull CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) {
Log.e(TAG, "error while reading the song file", e);
}
return dialog;
}