简体   繁体   English

与相机快门声音同时播放音频

[英]Playing audio simultaneously with camera shutter sound

How do I play a sound simultaneously with the camera shutter going off? 如何在相机快门关闭的同时播放声音?

In my application, I have an inset camera preview. 在我的应用程序中,我有一个嵌入式摄像机预览。 It takes 3 pictures automatically after 5 seconds of the activity starting. 活动开始5秒钟后,它将自动拍摄3张照片。 During this time the application is receiving a range of values via Bluetooth. 在这段时间内,应用程序正在通过蓝牙接收一系列值。 Everytime the values are greater than a preset threshold, the application plays a tone, which is done using MediaPlayer. 每当值大于预设阈值时,应用程序就会播放一个音调,这是使用MediaPlayer完成的。

The problem is that when the camera goes off, the shutter click sound seems to take over all the audio, and the tone being played stops and only resumes after the 3 shutter clicks. 问题在于,当相机关闭时,快门咔嗒声似乎会接管所有音频,并且播放的声音会停止并且仅在3次快门咔嗒声之后才会恢复。 I don't want to silence the camera shutter, so is there a way I can get the tone to play with shutter clicks? 我不想使相机的快门静音,那么有没有办法让我的音调随着快门的咔嗒声播放呢? This is all happening in one activity. 所有这些都是在一项活动中发生的。

Thanks 谢谢

One possible solution would be to use the hidden ENFORCED_AUDIBLE stream type for your tones. 一种可能的解决方案是对音调使用隐藏的ENFORCED_AUDIBLE流类型。 This is the stream type that the camera shutter sound most likely will use, so it won't be muted unless the shutter sound has been muted. 这是最有可能使用相机快门声音的流类型,因此除非快门声音被静音,否则它不会被静音。

Note that this stream type wasn't introduced until ICS (or maybe it was GB/HC, I can't say for sure off the top of my head), so it won't be compatible with every version of Android in existence. 请注意,直到ICS才引入此流类型(或者可能是GB / HC,我不能肯定地说),因此它与现有的每个Android版本都不兼容。 The integer value for this stream type identifier is 7, but if you want to check if exists / get its value programmatically you might be able to do so using reflection on the AudioSystem class. 此流类型标识符的整数值为7,但是如果您要检查是否存在/以编程方式获取其值,则可以使用AudioSystem类上的反射来做到这一点。

Here's an example of how this could be done: 这是如何完成此操作的示例:

public static boolean mHasEnforcedStream = true;
public static int STREAM_SYSTEM_ENFORCED = 0;

...

static
{        
    try
    {
        Class asClass = Class.forName("android.media.AudioSystem");
        Field sseField = asClass.getDeclaredField("STREAM_SYSTEM_ENFORCED");
        STREAM_SYSTEM_ENFORCED = sseField.getInt(null);
    }
    catch (Exception e)
    {
        mHasEnforcedStream = false;
    }
}


Keep in mind that if you use this stream type you'll always get your tones in the loudspeaker even if the user has eg a 3.5mm wired headset attached, and even if the user has put his/her phone in silent mode. 请记住,如果您使用此流类型,即使用户连接了3.5mm有线耳机,并且即使用户将手机置于静音模式,也始终会在扬声器中听到声音。

I think this is what you should need. 我认为这是您所需要的。 This should contain what you need. 这应该包含您所需要的。 The first link is probably more useful than the 2nd since you want to still have other sounds, though its possible you'd be able to disable the audio channel specific to the camera shuttle sounds. 第一个链接可能比第二个链接有用,因为您仍然希望有其他声音,尽管有可能您可以禁用特定于相机穿梭声音的音频通道。

Well since I am still new to programming, I would do a google search on what files give off the camera sound, and I would put in your app to where it would rename those files with different extension so the sound would not go off and have them rename back to the original files. 好吧,因为我还是编程的新手,所以我会在Google上搜索哪些文件会发出摄像头声音,然后将您的应用程序放到它会重命名具有不同扩展名的文件的位置,这样声音就不会消失并具有它们重命名回原始文件。 OR I would look on how to make the camera silent through changing the camera values. 或者,我将研究如何通过更改相机值使相机静音。 I know on my Samsung Galaxy SIII I had to change the camera file names. 我知道我必须在三星Galaxy SIII上更改相机文件名。 (sprint carrier) (冲刺载体)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM