Play sounds? (mp3/wav)
I tried this code example:
public void AudioPlayback() { try { Player p = javax.microedition.media.Manager.createPlayer("rolling.wav"); p.realize(); VolumeControl volume = (VolumeControl)p.getControl("VolumeControl"); volume.setLevel(30); p.prefetch(); p.start(); } catch(MediaException me) { Dialog.alert(me.toString()); } catch(IOException ioe) { Dialog.alert(ioe.toString()); } }
'Rolling.mp3' and 'rolling.wav' files are in my file-res. But I m always get this response:
javax.microedition.media.MediaException
What have I done wrong?
Find a working example of code here:
public void play() { try { Class clazz = getClass(); InputStream is = clazz.getResourceAsStream("rolling.mp3"); Player player = javax.microedition.media.Manager.createPlayer(is, "audio/mpeg"); player.realize(); player.prefetch(); player.start(); } catch (Exception ex) { showMessage("Sound-Error!"); } }
One problem was that I had to use:
A player = javax.microedition.media.Manager.createPlayer (, "audio/mpeg" "");
Instead of
A player = Manager.createPlayer (that is, "audio/mpeg");
Tags: BlackBerry Developers
Similar Questions
-
Firefox when trying to play wavs/mp3s after clicking on link to it instead of display the dialog to open/download. In preferences on the applications tab, I always chose "ask" in the types of wav and mp3 files, but it does not solve this problem.
This has happened
Each time Firefox opened
== I'm not sure
Firefox will play the file if you have a drive installed that supports the mime type that the server sends to this file.
See "File handling in Firefox 3 and SeaMonkey 2": http://kb.mozillazine.org/File_types_and_download_actions
-
vs game sound effects mp3 wav files
I'm working on a video game and I using OpenAL files and wav audio work.
I was just to add playback and noticed that the wav file is big enough 4 MB against against the original mp3 file 1 MB
I'm trying to get the game to work with mp3 files to save space (can not get this to work see other post)
But that got me thinking.
After doing a lot of reading on the web, I noticed that most sources recommend using wav to mp3 files
I would have thought 'space' could pose a problem for mobile applications like this, but that doesn't seem to be a problem in these discussions.
People don't like about the real size of bar? (transmission of effects and space on the shelf)
Should I care?
The folder bar is currently around 4-5 MB with the backing track, it would be 8-9 MB
Please note that I have already reduced the bitrate (and did some other stuff) to minimize the size of the file, there's the mp3 file is much smaller, the wav file.
I also appreciate that there is some legal and philosophical reasons to not use mp3 but I think only those technical.
Update
It turns out that the reason why he broke was a stupid mistake on my part
as soon as I stared it stopped crashing
After much trial and error I was able to do the work.
I am also able to play multiple mp3 files at one time.
I think I'll use a hybrid model, however, keep track of .wav for sound effects files and MP3 files for support. I find that the mp3 files do not seem to be too brave was the wav file and just out of sync wise they seem sometimes.
I'm also somewhat surpised that mmr_stop() is so expensive, it caused glitches in my game, but I moved it to a different thread, and everything seems fine.
-
Play an MP3 sound using its ByteArray
With AS3 we can do to load an MP3 file and play:
var sound: Sound = new Sound (new URLRequest ("sound.mp3"));
Sound.play();
It is very easy, but what happens if I already have all the ByteArray of this loaded MP3 and I just want to play?
Why cant AS3 have a simple method to simply pass the ByteArray works exactly as it works now passing a URLRequest?
In my case, I need it because I'm loading a ZIP file containing a bunch of MP3s and when decompressing them I can read the bytearray of each MP3 but I can't play them.
Have you tried loadCompressedDataFromByteArray in the Sound class?
Assuming you have the ByteArray already instantiated, try:
var sound: Sound = new Sound();
sound.loadCompressedDataFromByteArray (mp3Bytes, mp3Bytes.length);
Sound.play();
-
Play sounds on RadioButtonField Select
Hello
I have 7-8 audio file (*.mp3) and I provide a feature in my application that the user can select the audio file that he wants on gettting no msg.
I got that how make an action on RBF select but now I want to play a sound on RBF select.
I M still able to vibrate the phone on select any file, but how can I play a sound?
I use this method, but its does not work. Is something wrong with that?
/**
* Play music
@param MediaName track name
*/
{} public void play (String MediaName)
First we need to find the supported content types
String [] types = Manager.getSupportedContentTypes (null);
for (cnt int = types.length - 1; cnt > = 0; cnt-) {}
If (types [cnt].equals("audio/mpeg")) {}
This example shows the playback of an MP3 file that has been
added as a resource to the project
try {}
get the MP3 file
Class clazz = Class.forName ("resources");
InputStream is = clazz.getResourceAsStream ("/" + MediaName);
Create an instance of the reader of the InputStream
A player = javax.microedition.media.Manager.createPlayer (, "audio/mpeg" "");
Player.Realize ();
Player.prefetch ();
Start the player
Player.Start ();
} catch (Exception ex) {}
}
} ElseIf (types [cnt] .equals ("audio/x-wav")) {}
This is where you play wav files
} ElseIf (types [cnt] .equals ("audio / midi")) {}
This is where you play midi files
}}
}AND I M CALLS THIS METHOD AS
box 15:
Play ("Switch.mp3");
Alert.startVibrate (500);
break;
box 16:
play ("Whip.mp3");
Alert.startVibrate (500);
break;I m putting all its file in the folder resources project.
can I know what this line means: Class clazz = Class.forName ("resources").
try like this:
getClass ().getResourceAsStream("/"+medianame)
-
Satellite 1690cdt: his problem - cannot play any mp3
Hello
I have an old 1690cdt that works just right. the only problem I want to solve, is that the sound does not work.
If I run the windows media player, it says "no audio hardware available. I can't play any mp3 either.
If I put an audio cd in the cdrom drive, it plays.
If I look at the configuration of the system, there is an audio WDM crystal soundfusion cs4281 installed. According to the specifications, this should be the sound card.
I tried updating the driver, but it does not work
I can do, or is it just broken?
Sincerely,
Gerard
Hello
In my opinion, the sound card is ok. You need only a MP3 for Windows Media Player codec. I use the Winamp application to play the Mp3 files. This very nice program, I m very happy. Try to install it and check if it of possible to read mp3.
-
Play sounds in the order using MediaPlayer
Hello. How to play sounds in order?
For now, here are my code.
I have a MediaPlayer component as an attached object
http://developer.BlackBerry.com/native/reference/Cascades/bb__multimedia__mediaplayer.html
attachedObjects :[ MediaPlayer{ id: sound sourceUrl: "asset:///sounds/sound1.mp3" } ]
Then I have a button. Here is what my code for it
Button{ id: play text: "Play Sequence" onClicked :{ sound.sourceUrl = "asset:///sounds/sound1.mp3" sound.play(); sound.sourceUrl = "asset:///sounds/sound2.mp3" sound.play(); sound.sourceUrl = "asset:///sounds/sound3.mp3" sound.play(); } }
What goes wrong.
The code runs after 1 second about, cut the next sound. I'm doing his next game, after the end of his previous.
The sounds are not finished because play() is not a call blocking. Once you call the play() function it will start playing the sound and return immediately to the following line of code in the QML. If the next line is a call to the play() still it will have precedence over previous sound, i.e. If you think logically about what you need in an application, you would not have the sound of a doorbell 2 seconds later, play just because you play already a sound, you would stop, as it does.
My suggestion to use a selection intended to use the MediaPlayer playlist function, that you implemented will obviously suffer from the same problem for the above reason. A playlist is a separate file that contains a list of media you want to play and can be in different formats.
My other suggestion of using onPlaybackCompleted does not seem to have been followed by you, but is probably the easiest to implement.
MediaPlayer { id: mediaPlayer onPlaybackCompleted: { count = count + 1; var s = count; mediaPlayer.setSourceUrl("asset:///sounds/sound" + s + ".mp3"); mediaPlayer.play(); } }
Where count is a comprehensive, defined property to 1 in your QML file and you have some relaxation (onCreationCompleted or clicking a button) to start the first play().
-
Firefox does not play sound in any HTML5 player.
When trying to play any sample of any album sold in Bandcamp.com the player starts to play, but there is no sound. Meanwhile, other browsers it plays very well.
I use the last FF, I tried to disable various addons and plugins, but it did not help (they are not sound related in any case).
I run on Win8x64.
Update: the sound plays very well everywhere else on Firefox. YouTube, etc. He plays everywhere except Bandcamp.
And the Bandcamp player is not Flash, it has nothing but associated with Flash. It's the HTML5 player.
SOLVED
Finally, after hundreds of hours I fixed it and Firefox plays sound in HTML5, YouTube (HTML5 mode), SoundCloud, Bandcamp and etc.
It takes: right click on your speaker icon / in the system tray and select playback devices, go to properties of speakers (one that is green-checked, also turn off the reds, as appropriate), then go to improvements and check Disable all sound effects. And that of it, restart the browser and enjoy.
In short: Volume mixer-> peripheral reading-> reading tab-> properties-> improvements speakers-> disable all sound effects-> restart of the browser.
I use latest stable Firefox 23.0.1 on Windows 8 x 64 (but Firefox is 32-bit).
In addition, if didn't need help, make sure that you have media.windows - media - foundation.enabled value 'true' about: config.
You should also have a few decent codecs installed on your machine, I have VLC Player and it comes with lots of built-in codecs. Also make sure you have VLC Web Plugin active in Add-ons-> Extensions (always activate)
So the answer is which a problem is who? Is Firefox? Or Windows 8? Or my fault of Realtek audio drivers? (In any case without disabling sound effects, HTML5 works fine in another browser, so I blame this nonsense for additional configurations in the audio settings of Windows with Firefox)
So pretty much it.
See you soon,.
rhazor -
Pavilion DV4: Laptop plays sound through headphones but not by internal speakers
Audio was working fine on my laptop, when suddenly the laptop would not play sound with internal speakers. If I plug in headphones sound is fine. Execution of control panel of configuration/sounds shows 'Speakers and dual headphone - IDT High Definition Audio CODEC' enabled and set as the default device, as well as "independent double headphones" (enabled by default but not) and 'SPDIF (Digital Out via HP docking station)' disabled. What can be wrong?
Cure the problem by uninstalling the CODEC driver, then restart Windows then reinstalled, and now things are ok again.
-
How can I get iPhone play sound of favorite when text DND?
Hello
How can I get iPhone play sound of favorite when text DND?
It plays the ringtone for a call when DND of a favorite but not identified a favorite texts me
Thanks in advance
You do not have. Notifications for all the messages are deleted when DND is turned on.
-
Download, record, play the MP3 on the iphone 6
For my work, I need to record and play back mp3s on my iphone 6 s. How can I do that with iOS 9.2.1 (13D 15)? I have the URL and they play well on the Internet but I need to read files on the ground away from any connection. So far this community seems to favor a complex of software patches third-party mix. Apple has a recommended method?
Daveyeamans wrote:
For my work, I need to record and play back mp3s on my iphone 6 s. How can I do that with iOS 9.2.1 (13D 15)? I have the URL and they play well on the Internet but I need to read files on the ground away from any connection. So far this community seems to favor a complex of software patches third-party mix. Apple has a recommended method?
Save you the mp3 in your iTunes library and then you sync your phone.
-
Windows Media Player 11 won't play CD, MP3, WMA etc. error C00D11B1.
Windows Media Player 11 won't play CD, MP3, WMA etc. error C00D11B1. I tried MS solve this problem, uninstalling, reinstalling, etc. Same problem on 2 computers. Winamp and Itunes play fine, its not hardware or drivers. Windows XP SP3 & Media Player 11 is perfectly up-to-date.
Hello
· Which Microsoft difficulty he makes you run?
You can check the link below which holds information about the error: C00D11B1: http://www.microsoft.com/windows/windowsmedia/player/webhelp/default.aspx?&mpver=11.0.5358.4827&id=C00D11B1&contextid=71&originalid=C00D0BB8
-
Media Player
I have just updated to Windows Media Player 11. I have a .avi file that only plays sound with no video. I'll see a message asking me to information center to display information about the file being played. Thank youDownload codecs here: -.
http://www.DivX.com/en/software/DivX-plus/Codec-PackOtherwise, you can download and install VLC: -.
http://www.videolan.org/VLC/download-Windows.html -
Media Player 11 plays sound but no video dvd XP OS
I have the nvidia decoder installed, but when I try to play a DVD I'm unable to see the video. Plays sound, but no video. I'm on Windows XP OS
Hi Jen,
seems that all codecs are not installed (normally you should not have to pay for a codec, I would check and make sure that no other only files where installed) done everything, try this:
http://www.Microsoft.com/download/en/details.aspx?displaylang=en&ID=507
hope this helps,
Eddie B. -
try to save a file using Sound Recorder .wav
I get a "not enough memory to complete this operation" error message when you try to save a file using Sound Recorder .wav
Maybe you are looking for
-
Pro-100 manual feed tray Canon does not load paper 13 x 19?
When I go to print on paper 13 x 19 through the manual feed tray of orange light always lit flashes twice. I have to press the orange flashing light so that the paper through and start printing.
-
Download the file keeps freezing
whenever I try to go to my downloads in my documents folder he maintains the gel and said that there was a mistake im not very good with computers even though I can usually gat by if someone could help me with this I would be very gratful thanks
-
How do I network a printer between XP and a Windows 7 computer?
I'm running Windows XP on my desktop and I want to connect my Epson printer to my laptop that runs Windows 7 How to accomplish this? I am running Windows XP Home version on my desktop computer and I would like to connect my Epson SX400 printer to my
-
Laptop HP 15 AF131DX: unable to connect to my wifi
my wireless stop working, I tried toubleshooting, tuning on my router, and etc, I think that my driver has stop working how can I get this fix
-
I need to buy a CD for my HP Pavilion dv6-2170us Entertainment Notebook recovery disc, because I messed up my operating system by installing a different window 7. No idea how is the CD & who do I contact to get a?