I am using JavaSound with Mp3SPI support.
The one I am using is JavaZoom
http://www.javazoom.net/mp3spi/mp3spi.html
When I create an AudioFileFormat from a file constructor I can get the duration of the mp3.
File file = new File("path/to/file.mp3");
AudioFileFormat format = AudioSystem.getAudioFileFormat(file);
format.properties().get("duration"); // works fine
But I have a file in memory and I cannot write it to disk...So when I create the AudioFileFormat from an InputStream I dont get the duration.
Heres my code:
ByteArrayInputStream barray = fromNetwork();
AudioFileFormat format = AudioSystem.getAudioFileFormat(barray);
format.properties().get("duration"); // does not work
But if I try to play the audio, it works fine.
Any idea how can I do that?
I used mp3agic and everything worked fine.
Mp3Agic
ByteArrayInputStream ba = IOUtil.toByteArrayInputStreamUntilTheEnd(new FileInputStream(file));
InputStream is = new InputStream(ba);
Mp3Metadata md = new Mp3Metadata(is);
Related
I am attempting to modify a Presentation file with Aspose.Slides.
var fileMemoryStream = new MemoryStream();
await fileMemoryStream.WriteAsync(file.FileData, 0, file.FileData.Length);
Presentation pres = new Presentation(fileMemoryStream);
IDocumentProperties pptProperties = pres.DocumentProperties;
pptProperties.Title = "test";
pres.Save(fileMemoryStream, Aspose.Slides.Export.SaveFormat.Pptx);
fileMemoryStream.Position = 0;
fileData = fileMemoryStream.ToArray();
var contentType = fileProperties.MimeTypes.ContainsKey(file.Extension) ? fileProperties.MimeTypes[file.Extension]: "application"+file.Extension.Replace(".", "/");
var fileConvert = File(fileData, contentType, exemplarFile.DownloadName + file.Extension);
Ff I comment out the pres.Save line, the file works. If I don't, it won't open and I'm left with the message below.
"Powerpoint found a problem with content in path.pptx. Powerpoint can attempt to repair the presentation."
If I comment out pptProperties.Title = "test";, it does not work. setting the fileMemoryStream to zero at the beginning does not work. I must be missing a step in the Aspose process, or the memorystream process. Any ideas?
Note: the file being tested is a pptx file and the Mimetype is correct
application/vnd.openxmlformats-officedocument.presentationml.presentation
I'm not sure what was happening, but saving the pres to a new MemoryStream instead of the current one worked.
If anyone has an idea as to why this is feel free to post, but this is what solved this.
In reference to this question: NoDriver calling acmFormatSuggest on Azure
My hosting server does not allow me to install anything or register dlls. I am using Naudio to mix to mp3 files and it gave me the error NoDriver calling acmFormatSuggest.
I downloaded and installed Nlayer in my application and modified the code to look like this:
var builderBackground = new Mp3FileReader.FrameDecompressorBuilder(wf => new Mp3FrameDecompressor(wf));
var builderMessage = new Mp3FileReader.FrameDecompressorBuilder(wf => new Mp3FrameDecompressor(wf));
Mp3FileReader mpbacground = new Mp3FileReader(ThumbAudioMP3, builderBackground); Mp3FileReader mpMessage = new Mp3FileReader(stream, builderMessage);
background = WaveFormatConversionStream.CreatePcmStream(mpbacground);
message = WaveFormatConversionStream.CreatePcmStream(mpMessage);
var mixer = new WaveMixerStream32(); var messageOffsetted = new WaveOffsetStream(message, TimeSpan.FromSeconds(0), TimeSpan.Zero, TimeSpan.FromSeconds(seconds));
I get the same NoDriver calling acmFormatSuggest error in the line WaveFormatConversionStream.CreatePcmStream(...
Can someone tell me how I should be doing this? Any documentation on Nlayer?
You don't need the WaveFormatConversionStream.CreatePcmStream lines. The Mp3FileReader classes will already emit PCM.
I've been looking into source code of Research Kit Example called ORKTest:
if (type.integerValue == ORKConsentSectionTypeDataGathering) {
/*
Tests PDF content instead of text, HTML for Learn More.
*/
NSString *path = [[NSBundle mainBundle] pathForResource:#"SAMPLE_PDF_TEST" ofType:#"pdf"];
consentSection.contentURL = [NSURL URLWithString:path];
}
It used a local PDF file path in .contentURL,and I'd like to replace it with a online PDF url such as http://examle.com/file/example.pdf
consentSection.contentURL = NSURL.fileURLWithPath("http://example.com/file/example.pdf")
or
consentSection.contentURL = NSURL.fileURLWithPath("example.com/file/example.pdf")
but only got an empty page(the url that I used worked fine on browser,just a pdf file).
Anyone got any ideas,please?
NSURL.fileURLWithPath only works with local files. You have to put it in app's sandbox, then ask consentSection to load it.
I have an Crypto.Cipher.AES.AESCipher object which i would like to save in a file.
But when i try to save it to a file i alway get the following error.
pickle.PicklingError: Can't pickle '_AES' object: <_AES object at 0x0000000002320430>
I tried the following to save the object:
dill.dump(object, open("save.p", "w"))
and I also tried:
pickle.dump(object, open("save.p", "wb")) which also gives a similar error
I created the AES object with the following:
BLOCK_SIZE = 32
secret = os.urandom(BLOCK_SIZE)
cipher = AES.new(secret)
This cipher i would like to save in a file and read it out again.
Is there a way to store such objects?
So I have an instance of Liquidsoap, which I am using to stream to an Icecast server.
I'd like to record any live broadcasts that take place automatically, which I am now doing and is working well.
What I'd like to do is use the metadata (specifically the songname) of the live show when creating the mp3 archive.
#!/usr/local/bin/liquidsoap
set("log.file",true)
set("log.file.path","/var/log/liquidsoap/radiostation.log")
set("log.stdout",true)
set("log.level",3)
#-------------------------------------
set("harbor.bind_addr","0.0.0.0")
#-------------------------------------
backup_playlist = playlist("/home/radio/playlists/playlist.pls",conservative=true,reload_mode="watch")
output.dummy(fallible=true,backup_playlist)
#-------------------------------------
live_dj = input.harbor(id="live",port=9000,password="XXX", "live")
date = '%m-%d-%Y'
time = '%H:%M:%S'
output.file(%mp3, "/var/www/recorded-shows/#{Title} - Recorded On #{date} At #{time}.mp3", live_dj, fallible=true)
#time_stamp = '%m-%d-%Y, %H:%M:%S'
#output.file(%mp3, "/var/www/recorded-shows/live_dj_#{time_stamp}.mp3", live_dj, fallible=true)
#-------------------------------------
on_fail = single("/home/radio/fallback/Enei -The Moment Feat DRS.mp3")
#-------------------------------------
source = fallback(track_sensitive=false,
[live_dj, backup_playlist, on_fail])
# We output the stream to icecast
output.icecast(%mp3,id="icecast",
mount="myradio.mp3",
host="localhost", password="XXX",
icy_metadata="true",description="cool radio",
url="http://myradio.fm",
source)
I have added #{title} where I would like my song title to appear, sadly though I am unable to get this populate.
My Dj's use BUTT and the show title is connected as part of their connection, so the data should be available pre recording.
Any advice is much appreciated!
This is far from being as easy as it seems.
The title metadata is dynamic, thus not available as a variable on script initialization
The filename argument of output.file is compiled when the script is initialized
A solution would consist in:
Defining a variable reference title to populate with live metadata
Output to a temporary file
Rename the file on close using on_close argument with output.file (in this case, we can just prepend the title)
This would give the following code (on a Linux box, change mv with ren on Windows):
date = '%m-%d-%Y'
time = '%H:%M:%S'
# Title is a reference
title = ref ""
# Populate with metadata
def get_title(m)
title := m['title']
end
live_dj = on_metadata(get_title,live_dj)
# Rename file on close
def on_close(filename)
# Generate new file name
new_filename = "#{path.dirname(filename)}/#{!title} - #{basename(filename)}"
# Rename file
system("mv '#{filename}' '#{new_filename}'")
end
output.file(on_close=on_close, %mp3, "/var/www/recorded-shows/Recorded On #{date} At #{time}.mp3", live_dj, fallible=true)
I tested a similar scenario and it works just well. Just beware that this will create a new file every time a DJ disconnects or updates the title. Also keep in mind that time stamps will be resolved by output.file.
This is based on the following example from a Liquidsoap dev: https://github.com/savonet/liquidsoap/issues/661#issuecomment-439935854)