当前位置:网站首页>Solution: prompt "unsupported video format" when inserting avi format video into the message

Solution: prompt "unsupported video format" when inserting avi format video into the message

2022-07-07 23:14:00 Full stack programmer webmaster

Hello everyone , I meet you again , I'm the king of the whole stack .

【 Test steps 】: New information . Join in AVI Format video

【 Test results 】: A prompt pops up when you join “unsupported video format”

This problem mainly refers to the fact that nowadays Mobile MMS video attachments do not support this AVI Video format , So we track the code through the operation process , lookup “unsupported video format” Where it's produced .

We start from the add attachment interface ComposeMessageActivity Class onActivityResult() Method start .

–》onActivityResult() The calling code is as follows :

case REQUEST_CODE_ATTACH_VIDEO: if (data != null) { mAttachFileUri = data.getData(); addVideoAsync(mAttachFileUri, false); } break;

–》addVideo()–》setAttachment()<WorkingMessage.java> The calling code is as follows :

result = append ? appendMedia(type, dataUri, slideShowEditor) : changeMedia(type, dataUri, slideShowEditor);

–》changeMedia()–》internalChangeMedia()–》changeVideo()<SlideshowEditor.java>

–》new VideoModel()<TAG 1-1>

public VideoModel(Context context, Uri uri, RegionModel region) throws MmsException { this(context, null, null, uri, region); initModelFromUri(uri); checkContentRestriction(); }

–》initModelFromUri()<VideoModel.java> The calling code is as follows :

private void initModelFromUri(Uri uri) throws MmsException { String scheme = uri.getScheme(); if (scheme.equals(“content”)) { initFromContentUri(uri); } else if (uri.getScheme().equals(“file”)) { initFromFile(uri); } initMediaDuration(); }

The above code is added by Log For the output , there scheme The value of is “file”.

–》initFromFile()

private void initFromFile(Uri uri) throws MmsException { String path = uri.getPath(); mSrc = path.substring(path.lastIndexOf(‘/’) + 1); MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton(); String extension = MimeTypeMap.getFileExtensionFromUrl(mSrc); if (TextUtils.isEmpty(extension)) { // getMimeTypeFromExtension() doesn’t handle spaces in filenames nor can it handle // urlEncoded strings. Let’s try one last time at finding the extension. int dotPos = mSrc.lastIndexOf(‘.’); if (0 <= dotPos) { extension = mSrc.substring(dotPos + 1); } } mContentType = mimeTypeMap.getMimeTypeFromExtension(extension.toLowerCase()); // It’s ok if mContentType is null. Eventually we’ll show a toast telling the // user the video couldn’t be attached. if (TextUtils.isEmpty(mContentType)) { throw new MmsException(“Type of media is unknown.”); }

if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) { Log.v(TAG, “New VideoModel initFromFile created:” + ” mSrc=” + mSrc + ” mContentType=” + mContentType + ” mUri=” + uri); } }

In the above code mContentType Assign a value , Here we go through Log Output ,mContentType The value of is “video/x-msvideo”.

Next, proceed to the constructor <TAG1-1> The method in checkContentRestriction().

protected void checkContentRestriction() throws ContentRestrictionException { ContentRestriction cr = ContentRestrictionFactory.getContentRestriction(); cr.checkVideoContentType(mContentType); }

–》checkVideoContentType()<CarrierContentRestriction.java>

public void checkAudioContentType(String contentType) throws ContentRestrictionException { if (null == contentType) { throw new ContentRestrictionException(“Null content type to be check”); }

if (!sSupportedAudioTypes.contains(contentType)) { throw new UnsupportContentTypeException(“Unsupported audio content type : “ + contentType); } }

The code marked in bold in the above code is the problem of test description . We then analyze the code in the static statements in this class .

sSupportedVideoTypes = ContentType.getVideoTypes();

Finally, we finally arrived ContentType.java class , And it is found that there is no support for this video format in this class . So add the following code to support .

……

public static final String VIDEO_UNSPECIFIED = “video/*”; public static final String VIDEO_3GPP = “video/3gpp”; public static final String VIDEO_3G2 = “video/3gpp2”; public static final String VIDEO_H263 = “video/h263”; public static final String VIDEO_MP4 = “video/mp4”; public static final String VIDEO_X_MSVIDEO = “video/x-msvideo”;

……

// add supported video types sSupportedVideoTypes.add(VIDEO_X_MSVIDEO); sSupportedVideoTypes.add(VIDEO_3GPP); sSupportedVideoTypes.add(VIDEO_3G2); sSupportedVideoTypes.add(VIDEO_H263); sSupportedVideoTypes.add(VIDEO_MP4);

……

OK!

Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/116200.html Link to the original text :https://javaforall.cn

原网站

版权声明
本文为[Full stack programmer webmaster]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207072149334622.html