|
demo
这个论坛上传附件,貌似IE only。贴代码吧。
import android.util.Log;
import com.taixin.idtv.*;
import com.taixin.idtv.si.*;
import org.ngb.toolkit.channelscan.*;
import org.ngb.broadcast.dvb.tuning.*;
import org.ngb.broadcast.dvb.si.*;
public class DvbcScan {
static final String TAG = "DvbcScanNit";
public static final int SCAN_TYPE_MANUAL = ChannelScanEngine.CHANNELSCAN_TYPE_MANUAL;
public static final int SCAN_TYPE_NIT = ChannelScanEngine.CHANNELSCAN_TYPE_NIT;
ProgramManager progmgr;
DvbcScanListener listener;
ChannelScanEngine engine = null;
int scanType = -1;
int freqMHz, symKbps, qam;
int tvcnt, radiocnt, freqcnt;
int curfreqcnt;
public DvbcScan(int type) {
scanType = type;
}
public void setScanParams(int freqMHz, int symKbps, int qam) {
this.freqMHz = freqMHz;
this.symKbps = symKbps;
this.qam = qam;
}
public void setListener(DvbcScanListener listener) {
this.listener = listener;
}
public void start() {
tvcnt = radiocnt = freqcnt = curfreqcnt = 0;
try {
engine = ChannelScanEngine.createInstance();
} catch (Exception e) {
e.printStackTrace();
return;
}
DvbcTuningParameters[] param = new DvbcTuningParameters[1];
param[0] = new DvbcTuningParameters(freqMHz * 1000, qam + 1, symKbps);
engine.addChannelScanListener(scanlistener);
try {
engine.startScan(scanType, param);
} catch(Exception e) {
e.printStackTrace();
}
}
public void cancel() {
engine.cancel();
}
private ChannelScanListener scanlistener = new ChannelScanListener() {
public void processEvent(ChannelScanEvent event) {
if (event instanceof ChannelScanNITSuccessEvent) {
ChannelScanNITSuccessEvent nit = (ChannelScanNITSuccessEvent)event;
freqcnt = nit.getTransportStream().length;
}
else if(event instanceof ChannelScanSuccessEvent) {
ChannelScanSuccessEvent succ = (ChannelScanSuccessEvent)event;
SIService[] srvs = succ.getResult();
if (srvs != null) {
int tv = 0, radio = 0;
for (int i=0; i<srvs.length; i++) {
short type = srvs[i].getServiceType();
if (type == SIServiceType.SERVICE_TYPE_DIGITAL_TELEVISION)
tv += 1;
else if (type == SIServiceType.SERVICE_TYPE_DIGITAL_RADIO_SOUND)
radio += 1;
}
tvcnt += tv;
radiocnt += radio;
}
curfreqcnt += 1;
listener.OnDvbcScanEvent(curfreqcnt * 1.0f / freqcnt, tvcnt, radiocnt, DvbcScanListener.DVBC_SCAN_STATUS_SUCCESS);
}
else if(event instanceof ChannelScanFinishEvent) {
ChannelScanFinishEvent finish = (ChannelScanFinishEvent)event;
SIDatabase[] db = SIDatabase.getDatabase();
SIService[] services = db[0].listServices();
if (services != null) {
engine.saveScanResult();
progmgr = ProgramManager.getInstance();
progmgr.build(services);
progmgr.serialize();
TxDtvPlayer.getInstance().playDefault();
}
listener.OnDvbcScanEvent(1.0f, tvcnt, radiocnt, DvbcScanListener.DVBC_SCAN_STATUS_FINISH);
}
else {
ChannelScanFailureEvent fail = (ChannelScanFailureEvent)event;
Log.i(TAG, "scan failed, reason:" + fail.getReason());
curfreqcnt += 1;
listener.OnDvbcScanEvent(curfreqcnt * 1.0f / freqcnt, tvcnt, radiocnt, DvbcScanListener.DVBC_SCAN_STATUS_FAILED);
}
}
};
}
|
|