Office Hours — Today, August 29

Tuesday, August 27

Aug 29
7:25 PM
Mark M.
has entered the room
Mark M.
turned on guest access
7:45 PM
Ron
has entered the room
Ron
Hello to all!
Mark M.
hello, Ron!
how can I help you today?
Ron
View paste
We are using the SoundPool object to play short notification sounds. The notification sound is currently held in the raw directory. Now, we need to allow the user to select/download a sound of their choosing. We understand that it is stored in the Downloads folder on the SD card (we can see it there). We are having trouble using the load(path, int) method for the SoundPool object. It always returns null when we pass the path in. We've been to StackOverflow and think we've tried everything there. Is there something we are missing? It seems that this should be simple.The code we are currently using is:


String path1 = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString();

 soundID = soundPool.load(path1+"sound1.ogg", 1);
Mark M.
well, I always yell at people for using concatenation to create file paths
Ron
What is a better way?
Mark M.
use new File(Environment..., "sound1.ogg") to get the File
then convert that using getAbsolutePath() to a String
7:50 PM
Mark M.
that way, you are protected no matter whether the directory name has a trailing / or not
Ron
OK, I think I remember something about that (this is some old code I wrote 2 years ago) Any other suggestions?
Mark M.
otherwise, what you have seems OK
though I haven't used SoundPool personally
Ron
What do think about Media Player?
Mark M.
I typically think of reserving SoundPool for overlapping sounds, like game sound effects
MediaPlayer should work fine, if SoundPool continues to give you grief
Ron
We aren't playing music per se, just short notification sounds (clicks, beeps, etc).
Media Player says that it loads the sound in-line each time you play it, is that true?
Mark M.
yes
Ron
We would be concerned about multiple load times even though the sounds are short.
Mark M.
then try using the File constructor and see if it helps
Ron
Does the media player play method spawn off it's own thread or do we need to provide threading?
Mark M.
looking at the source code to SoundPool, they just turn around and create a File from the path anyway, if it doesn't start with http:/
MediaPlayer is automatically asynchronous for playback
7:55 PM
Mark M.
for loading the clip, you call prepare() (blocking) or prepareAsync() (non-blocking)
Ron
On the prepareAsync is there a callback to let us know when it is prepared?
Mark M.
yes
BTW, it is impossible for load() on SoundPool to return null, as the return type is int
Ron
Sounds good, I think we have enough to continue with, Thanks for the help. Over and out.
Ron
has left the room
Elad G.
has entered the room
Mark M.
hello, Elad!
how can I help you today?
Elad G.
Hey!
first of all
I love the book
Mark M.
great! thanks!
Elad G.
It's 3AM here right now(I stayed up this late to speak with you)
Mark M.
yeesh!
8:00 PM
Mark M.
I have some more friendly hours for you next week, then
Elad G.
So, I want to ask you about cwac camera
two things
Mark M.
sure! go ahead!
Elad G.
The first: Im trying to implement an Instagram like app for my company-> I don't need to much options- just the flash, autofouces and rotate camera and ofcourse previewing the picture to the user before he shoots the photo
8:05 PM
Mark M.
um, well, that should be OK with CWAC-Camera as it stands, assuming that by "rotate camera" you mean "support portrait and landscape"
I am still slogging through trying to determine which cameras need extra help with the portrait mode images
the way most Samsung and Motorola devices do
but your app should not need to worry about that -- that's my job in the library
Elad G.
View paste
I meant-> change camera :)
I got all of these to work -> I used the fragmet you supplied in the demo
and overriden the onCreateView: I added a frame layout and to it I added the camera view-> ontop of that I have a couple of relative layouts that hide the surface view...
Question is the resolution that I get is not optimum It's not perfect smooth
Mark M.
do you mean the resolution of the pictures that you take?
Elad G.
no
the preview
It's not as sharp as I want it to be
Mark M.
the preview image resolution that is chosen by default is based on a few criteria, including the aspect ratio of the desired picture resolution
you are welcome to override that in your CameraHost implementation (or SimpleCameraHost subclass) to use any valid preview resolution
8:10 PM
Mark M.
you might also wish to have mayUseForVideo() return false, as that drives SimpleCameraHost to use getPreferredPreviewSizeForVideo(), and I have had reports that this does not give a great result on some devices
Elad G.
you beat me to it..
:)
I did all of the above
I have a nice resolution now
but not perfect
Mark M.
I do not know what "perfect" would be, and I have even less idea how to help you get it
Elad G.
I'll play with it more
for me perfect is more sharp
like the android camera
the native one
Mark M.
then choose a higher preview resolution
Elad G.
I choose the highest -> Im using a nexus 4 for my tests-> and I get 720X1280
8:15 PM
Mark M.
then, by definition, that is all the better you can get
Elad G.
cool
the second thing->
Today I while debuggin my app on my nexus 4-> I left the camere fragment opened for a while, acouple of times. after Clicking shoot photo-> my device restarted!!
It didn't happend once
4-5 times
I didn't fully implemented the save photo to disk option
Mark M.
well, a device restart means a firmware bug -- there's nothing that we can do in an app that would cause that
if, at some point, you can give me steps that are assured to reproduce the problem, I will see if I can get it to happen on my Nexus 4
for example, if you can get this to happen with one of the demo apps
Elad G.
Ok
Two more
8:20 PM
Elad G.
after shooting the photo -> I want to crop the visible parts to the user(as I said I hide some parts with colored relative layouts), how would you suggest I implement this?
Mark M.
Bitmap.createBitmap()
or http://goo.gl/qSHP5A since that link didn't work
Elad G.
offset is where I start?
sorry
Wrong method
:)
cool
Mark M.
yeah, there are several createBitmap() flavors
Elad G.
Last question
Ron
has entered the room
Elad G.
I add an overlay to the image I have
Mark M.
(BTW, howdy, Ron -- be with you shortly!)
Ron
Hello, I'm back for more
Elad G.
Say a crown that you can place on someone's had
when I crop my Image I want to crop the crown with it
should I use the same method as above?
Mark M.
um, I guess so
if your end objective is to save a merged bitmap, with the photo and the crown, you might consider merging them before cropping
Elad G.
How do I do that?
8:25 PM
Mark M.
the only way I know off the top of my head would be to do it by hand, pixel by pixel
but I have never really researched this point
Elad G.
ok
Ill check it up
and about the bug
Ill try reproducing it
Mark M.
OK
Elad G.
10x for all!!
Mark M.
you are very welcome
Ron: do you have another question?
Ron
View paste

We used your earlier tip on our soundpool question and executed the following:


File file1 = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),"sound1.ogg");
String newpath = file1.getAbsolutePath();
	 	
soundID = soundPool.load(newpath, 1);

On 2 out of 3 devices this works fine but it doesn't work on our Motorola DROIDX running 2.3.4

Any possible suggestions?
Mark M.
what exactly are your symptoms?
Ron
returns a 0 value for the soundID
We did verify that the file is in the downloads directory
Mark M.
I take it that 0 is an invalid sound ID?
the docs do not say that's the case, which is why I ask
and, have you checked LogCat?
Ron
hmmm, we were under the impression that 0 was invalid. we will check on it. You can proceed on to next user
We will check logcat as well.
Mark M.
the one way I see that it would return 0 is if there's an exception reading the file, and there should be a message in LogCat for that
Ron
Gotcha, we will check on it.
Mark M.
well, that's a wrap for today's chat
the transcript will be posted shortly to http://commonsware.com/office-hours/
Ron
has left the room
Mark M.
the next chat is Tuesday, 4pm Eastern
have a pleasant, er, night! :-)
8:30 PM
Elad G.
has left the room
Mark M.
turned off guest access

Tuesday, August 27

 

Office Hours

People in this transcript

  • Elad Gelman
  • Mark Murphy
  • Ron