【操作步骤】:接收一条音频(系统音频,格式为ogg),点菜单键选择View slideshow
【测试结果】:不能播放,提示是否导入vCard
【预期结果】:可以播放
【备注】:附log 接收带图片、ogg格式音频 、视频幻灯片时也不能播放,提示是否导入vCard
经过分析和反复测试发现,该问题是由于电信运营商引起,该问题为移动发往本机联通网络,接收类型为application/oct-stream,但文件扩展名为ogg格式音频,因此导致该问题的产生,为了更全面的解决该模块下彩信接收功能这种有电信运营商之间的不兼容产生的问题,同时测试不同类型附件包括视频/音频/图片/名片等,在同时接受中国移动电信运营商发来的附件(包括图片/视频/音频等)测试发现,只有音频出现了类似的问题,因此在经过分析发现在获取接受附件的MIME是发现,vcard和ogg音频的contentType都是oct-stream;下面是数据截图:
因此我们在SlideshowModel类中的createFromMessageUri()方法中添加对附件文件扩展名的判断(红色为修改添加的内容);
public static SlideshowModel createFromPduBody(Context context, PduBody pb) throws MmsException {
SMILDocument document = SmilHelper.getDocument(pb);
// Create root-layout model.
SMILLayoutElement sle = document.getLayout();
SMILRootLayoutElement srle = sle.getRootLayout();
int w = srle.getWidth();
int h = srle.getHeight();
if ((w == 0) || (h == 0)) {
w = LayoutManager.getInstance().getLayoutParameters().getWidth();
h = LayoutManager.getInstance().getLayoutParameters().getHeight();
srle.setWidth(w);
srle.setHeight(h);
}
RegionModel rootLayout = new RegionModel(
null, 0, 0, w, h);
// Create region models.
ArrayList<RegionModel> regions = new ArrayList<RegionModel>();
NodeList nlRegions = sle.getRegions();
int regionsNum = nlRegions.getLength();
for (int i = 0; i < regionsNum; i++) {
SMILRegionElement sre = (SMILRegionElement) nlRegions.item(i);
RegionModel r = new RegionModel(sre.getId(), sre.getFit(),
sre.getLeft(), sre.getTop(), sre.getWidth(), sre.getHeight(),
sre.getBackgroundColor());
regions.add(r);
}
LayoutModel layouts = new LayoutModel(rootLayout, regions);
// Create slide models.
SMILElement docBody = document.getBody();
NodeList slideNodes = docBody.getChildNodes();
int slidesNum = slideNodes.getLength();
ArrayList<SlideModel> slides = new ArrayList<SlideModel>(slidesNum);
int totalMessageSize = 0;
boolean classCastFailed = false;
for (int i = 0; i < slidesNum; i++) {
// FIXME: This is NOT compatible with the SMILDocument which is
// generated by some other mobile phones.
SMILParElement par = (SMILParElement) slideNodes.item(i);
// Create media models for each slide.
NodeList mediaNodes = par.getChildNodes();
int mediaNum = mediaNodes.getLength();
ArrayList<MediaModel> mediaSet = new ArrayList<MediaModel>(mediaNum);
for (int j = 0; j < mediaNum; j++) {
SMILMediaElement sme = null;
try {
sme = (SMILMediaElement) mediaNodes.item(j);
} catch (ClassCastException e) {
classCastFailed = true;
Log.e(TAG, e.getMessage());
continue;
}
try {
MediaModel media = MediaModelFactory.getMediaModel(
context, sme, layouts, pb);
/*
* This is for slide duration value set.
* If mms server does not support slide duration.
*/
if (!MmsConfig.getSlideDurationEnabled()) {
int mediadur = media.getDuration();
float dur = par.getDur();
if (dur == 0) {
mediadur = MmsConfig.getMinimumSlideElementDuration() * 1000;
media.setDuration(mediadur);
}
if ((int)mediadur / 1000 != dur) {
String tag = sme.getTagName();
if (ContentType.isVideoType(media.mContentType)
|| tag.equals(SmilHelper.ELEMENT_TAG_VIDEO)
|| ContentType.isAudioType(media.mContentType)
|| tag.equals(SmilHelper.ELEMENT_TAG_AUDIO)) {
/*
* add 1 sec to release and close audio/video
* for guaranteeing the audio/video playing.
* because the mmsc does not support the slide duration.
*/
par.setDur((float)mediadur / 1000 + 1);
} else {
/*
* If a slide has an image and an audio/video element
* and the audio/video element has longer duration than the image,
* The Image disappear before the slide play done. so have to match
* an image duration to the slide duration.
*/
if ((int)mediadur / 1000 < dur) {
media.setDuration((int)dur * 1000);
} else {
if ((int)dur != 0) {
media.setDuration((int)dur * 1000);
} else {
par.setDur((float)mediadur / 1000);
}
}
}
}
}
SmilHelper.addMediaElementEventListeners(
(EventTarget) sme, media);
mediaSet.add(media);
totalMessageSize += media.getMediaSize();
} catch (IOException e) {
Log.e(TAG, e.getMessage(), e);
} catch (IllegalArgumentException e) {
Log.e(TAG, e.getMessage(), e);
}
}
// Add vcard and vcalendar when receive from other products
// without ref target in smil.
int partsNum = pb.getPartsNum();
for (int k = 0; k < partsNum; k++) {
PduPart part = pb.getPart(k);
String type=new String(part.getContentType());
if (type.toLowerCase().equals(ContentType.TEXT_VCARD.toLowerCase())||(type.toLowerCase().equals(ContentType.OCT_STREAM)&&isVCF(new String(part.getContentLocation())))) {
MediaModel vMedia = new VcardModel(context, new String(
part.getContentType()), new String(part.getContentLocation()),
part.getDataUri());
mediaSet.add(vMedia);
totalMessageSize += vMedia.getMediaSize();
break;
}else if (type.toLowerCase().equals(ContentType.TEXT_VCALENDAR.toLowerCase())) {
MediaModel tMedia = new UnsupportModel(context, new String(
part.getContentType()), new String(part.getContentLocation()),
part.getDataUri());
mediaSet.add(tMedia);
totalMessageSize += tMedia.getMediaSize();
break;
}
}
float duration = par.getDur();
if (duration < MIN_PAT_DURATION) {
duration = MIN_PAT_DURATION;
}
SlideModel slide = new SlideModel((int) (duration * 1000), mediaSet);
slide.setFill(par.getFill());
SmilHelper.addParElementEventListeners((EventTarget) par, slide);
slides.add(slide);
}
SlideshowModel slideshow = new SlideshowModel(layouts, slides, document, pb, context);
slideshow.mTotalMessageSize = totalMessageSize;
slideshow.registerModelChangedObserver(slideshow);
return slideshow;
}
/**
* @param fileName
* @return
*/
public static boolean isVCF(String fileName) {
if (fileName.lastIndexOf(".") != -1 && fileName.lastIndexOf(".") != 0) {
return( fileName.substring(fileName.lastIndexOf(".") + 1)).toLowerCase().equals("vcf");
} else {
return false;
}
}