blackberry - 黑莓手机如何录音?

标签 blackberry call

我想在黑莓中创建一个通话记录器应用程序。在这个论坛中搜索时,我得到了 call-recorder-in-blackberry这个链接。下面链接中给出的代码是可以理解的。

对于各位专家来说,这可能是一个愚蠢的问题,但我的问题是如何使用这段代码。我的意思是 MyScreen 对象将在 UIApplication 上工作。但是我怎样才能让我的模块在启动设备时启动,并在后台运行等待电话监听器调用。

<小时/>

我使用了下面的代码,它会记录通话,但前提是通话处于扬声器模式。现在我怎样才能在不进入扬声器模式的情况下做同样的事情呢?

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.RecordControl;

import net.rim.blackberry.api.phone.Phone;
import net.rim.blackberry.api.phone.PhoneCall;
import net.rim.blackberry.api.phone.PhoneListener;
import net.rim.device.api.system.Application;
import net.rim.device.api.ui.component.Dialog;

public class CatchCall extends Application implements PhoneListener {

    Player player;
    RecordControl recorder;
    private ByteArrayOutputStream output;
    byte[] data;
    boolean yes = false;
    int st;

    public CatchCall() {
        Phone.addPhoneListener(this);
    }

    public static void main(String[] args) {
        new CatchCall().enterEventDispatcher();
    }

    public void callAdded(int callId) {
    }

    public void callAnswered(int callId) {
    }

    public void callConferenceCallEstablished(int callId) {
    }

    public void callConnected(int callId) {

        // TODO Auto-generated method s
        PhoneCall phoneCall = Phone.getCall(callId);
        if (phoneCall != null) {
            if (yes)
                initPlay();
        }
    }

    public void callDirectConnectConnected(int callId) {
    }

    public void callDirectConnectDisconnected(int callId) {
    }

    public void callDisconnected(int callId) {
        // TODO Auto-generated method stub
        if (yes) {
            try {
                recorder.commit();

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            player.close();
            data = output.toByteArray();
            saveRecordedFile(data);
        }
    }

    public void callEndedByUser(int callId) {
    }

    public void callFailed(int callId, int reason) {
    }

    public void callHeld(int callId) {
    }

    public void callIncoming(int callId) {
        Dialog.ask(Dialog.D_YES_NO, "Are u sure to record this call");
    }

    public void callInitiated(int callid) {

        PhoneCall phoneCall = Phone.getCall(callid);
        if (phoneCall != null) {
            st = Dialog.ask(Dialog.D_YES_NO, "Are u sure to record this call");
            if (st == Dialog.YES)
                yes = true;
            else
                yes = false;
        }

    }

    public void callRemoved(int callId) {
    }

    public void callResumed(int callId) {
    }

    public void callWaiting(int callid) {
    }

    public void conferenceCallDisconnected(int callId) {
    }

    private void initPlay() {
        try {
            player = Manager.createPlayer("capture://audio");
            player.realize();
            recorder = (RecordControl) player.getControl("RecordControl");
            output = new ByteArrayOutputStream();
            recorder.setRecordStream(output);
            recorder.startRecord();
            player.start();
        } catch (Exception e) {
            Dialog.alert(e + "");
        }

    }

    public static boolean saveRecordedFile(byte[] data) {
        try {
            String filePath1 = System.getProperty("fileconn.dir.music");
            String fileName = "Call Recorder(";
            boolean existed = true;
            for (int i = 0; i < Integer.MAX_VALUE; i++) {
                try {
                    FileConnection fc = (FileConnection) Connector.open(filePath1 + fileName + i + ").amr");
                    if (!fc.exists()) {
                        existed = false;
                    }
                    fc.close();
                } catch (IOException e) {
                    Dialog.alert("unable to save");
                    return existed;
                }
                if (!existed) {
                    fileName += i + ").amr";
                    filePath1 += fileName;
                    break;
                }
            }
            System.out.println(filePath1);
            System.out.println("");
            FileConnection fconn = (FileConnection) javax.microedition.io.Connector .open(filePath1, javax.microedition.io.Connector.READ_WRITE);
            if (fconn.exists())
                fconn.delete();
            fconn.create();

            OutputStream outputStream = fconn.openOutputStream();
            outputStream.write(data);
            outputStream.close();
            fconn.close();
            return true;
        } catch (Exception e) {
        }
        return false;
    }
}

最佳答案

实际上黑莓无法直接进行通话录音。据我所知,发布的代码是在使用扬声器通话时进行通话录音。这意味着如果移动设备有扬声器,则调用扬声器并录制该声音。看看这个讨论,Call recorder in Blackberry.

关于blackberry - 黑莓手机如何录音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18082722/

相关文章:

c - 难以理解 c 中的 func(&_)

ASP.NET 从用户控件 (ASCX) 调用 (ASPX) 中的方法?

javascript - 中止ajax调用javascript

iphone - 创建一个监听来电事件的移动应用

blackberry - 黑莓开发的最佳实践是什么,以覆盖最广泛的智能手机?

blackberry - 创建一个每个都具有Focusable的GridFieldManager?

php - __call 魔法在 PHP 中创建新类

c - linux系统c引用

android - 我们是否需要为 android 和 ios 使用不同的 DFP 单元 ID

user-interface - 类似图像映射的 Blackberry 控件 - CLDC 应用程序