Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed..... #486

Merged
merged 3 commits into from Feb 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -30,6 +30,7 @@
import java.io.IOException;
import java.net.URISyntaxException;
import java.security.InvalidParameterException;
import java.util.HashMap;
import java.util.Map;

import com.rhomobile.rhodes.Logger;
Expand All @@ -56,6 +57,7 @@ public class CameraActivity extends BaseActivity implements OnClickListener {
private CameraPreview mPreview;
private OrientationEventListener mOrientationListener;
private int mRotation = 0;
MediaPlayer _shootMP = null;

@Override
protected void onCreate(Bundle extras) {
Expand Down Expand Up @@ -93,7 +95,8 @@ protected void onResume() {
protected void onPause() {
Logger.T(TAG, "onPause");
mPreview.stopPreview();
mOrientationListener.disable();
mOrientationListener.disable();
_shootMP.release();
super.onPause();
}

Expand All @@ -107,4 +110,20 @@ public void onClick(View view) {
camera.doTakePicture(this, (mRotation + 45)/90 * 90);
}
}

public void playMusic(String musicPath)
{
AudioManager meng = (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
int volume = meng.getStreamVolume( AudioManager.STREAM_NOTIFICATION);

if (volume != 0)
{

if (_shootMP == null)
// _shootMP = MediaPlayer.create(getBaseContext(), Uri.parse("file:///sdcard/malaya/sleep_away.3gpp"));
_shootMP = MediaPlayer.create(getBaseContext(), Uri.parse(musicPath));
if (_shootMP != null)
_shootMP.start();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to release media player object when stop playing.

}
}
}
Expand Up @@ -10,6 +10,7 @@
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
Expand Down Expand Up @@ -64,8 +65,10 @@ static class RawSize implements ICameraObject.ISize {

protected class TakePictureCallback implements Camera.PictureCallback {
private Activity mPreviewActivity;
private CameraActivity mcameraActivity;
TakePictureCallback(Activity previewActivity) {
mPreviewActivity = previewActivity;
mcameraActivity = (CameraActivity) previewActivity;
}
@Override
public void onPictureTaken(byte[] data, Camera camera) {
Expand All @@ -78,8 +81,13 @@ public void onPictureTaken(byte[] data, Camera camera) {
if (propertyMap == null) {
throw new RuntimeException("Camera property map is undefined");
}

String outputFormat = propertyMap.get("outputFormat");

if(propertyMap.containsKey("captureSound")){
mcameraActivity.playMusic(propertyMap.get("captureSound"));
}

String filePath = null;
Uri resultUri = null;
if (outputFormat.equalsIgnoreCase("dataUri")) {
Expand Down Expand Up @@ -139,8 +147,7 @@ public void onPictureTaken(byte[] data, Camera camera) {
}
bitmap.recycle();
mPreviewActivity.finish();

}
}
}

protected Camera getCamera() { return mCamera; }
Expand Down Expand Up @@ -206,20 +213,18 @@ public void stopPreview() {
public ISize setPreviewSize(int width, int height) {
Camera camera = getCamera();
Camera.Parameters parameters = camera.getParameters();
Intent intent = new Intent();
List<android.hardware.Camera.Size> sizes = camera.getParameters().getSupportedPictureSizes();
android.hardware.Camera.Size maxSize=sizes.get(0);
if(getActualPropertyMap().containsKey("desiredWidth") || getActualPropertyMap().containsKey("desiredHeight")){
int desired_width = Integer.parseInt(getActualPropertyMap().get("desiredWidth"));
int desired_height = Integer.parseInt(getActualPropertyMap().get("desiredHeight"));
int desired_height = Integer.parseInt(getActualPropertyMap().get("desiredHeight"));
if(desired_width > 0 && desired_width <= maxSize.width && desired_height > 0 && desired_height <= maxSize.height){
Camera.Size previewSize = getOptimalPreviewSize(parameters.getSupportedPictureSizes(), desired_width, desired_height);
Logger.T(TAG, "Selected size: " + previewSize.width + "x" + previewSize.height);
parameters.setPreviewSize(previewSize.width, previewSize.height);
}
else{
//Handle error message
intent.putExtra("error", "Please enter a valid desired value");
else{
parameters.setPreviewSize(320, 240);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you decided to not inform developer about wrong parameter value? The behavior at hi-res devices will be strange?...

}
}
else{
Expand Down