从Java中的网址获取音频持续时间

时间:2018-08-14 07:51:26

标签: java audio

我需要从Java中音频的URL中获取音频的持续时间,但是找不到找到它的方法。 有人可以建议如何做吗?

2 个答案:

答案 0 :(得分:0)

我认为应该这样做:

 Protected Sub OpenBTN_Click(sender As Object, e As EventArgs) Handles OpenBTN.Click
    Try
        FinalFile = dir & Field2.ToString() & "\" & DateList.SelectedItem.Text & "\" & AccList.SelectedItem.Text
        Label2.Text = FinalFile 'FinalFile is the path'
        Dim P = Process.Start(FinalFile)


    Catch ex As Exception

        filee.Text = ex.Message 'this is showiing me the exception'
    End Try

End Sub

答案 1 :(得分:0)

经过研究,我找到了这个问题的答案,并发布了答案,以便其他人也可以这样做。

String filePrefix = FileUtils.getTempDirectoryPath() + File.separator;

        URL audioURL = new URL(url);
        File destination = new File(filePrefix + UUID.randomUUID().toString());  // To store the file at a certain destination for temporary usage
        FileUtils.copyURLToFile(audioURL, destination);

        IsoFile isoFile = new IsoFile(destination.getAbsolutePath());

        double lengthInSeconds = (double)
                isoFile.getMovieBox().getMovieHeaderBox().getDuration() /
                isoFile.getMovieBox().getMovieHeaderBox().getTimescale();

        try {
            System.out.println("Length of audio in seconds === " + lengthInSeconds);
            destination.delete();
        } catch (Exception e) {
            e.printStackTrace();
        }

注意::apache.commons存储库中的FileUtils,coremedia.iso存储库中的IsoFile