Created
August 18, 2011 02:15
-
-
Save kosso/1153138 to your computer and use it in GitHub Desktop.
A Titanium module for Android to get the full path of an audio or video contentUri
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| MediaQuery Module for Appclerator Titanium : Android | |
| Author : Kosso | |
| Date : August 18, 2011 | |
| Updated : August 07, 2012 - Fixes and changes for newer Ti SDK since this was written. | |
| More info re changes/porting : https://wiki.appcelerator.org/display/guides/Android+Module+Porting+Guide+for+1.8.0.1 | |
| Description : | |
| Provides a method to get the file file path of an audio or video file recorded with the | |
| "android.provider.MediaStore.RECORD_SOUND" or "android.media.action.VIDEO_CAPTURE" actions. | |
| These actions return a content://providerUri/contentId string in the app, so we pass the contentId | |
| to the required providerUri using two methods depending on which intent activity is being used to return a String back to the app: | |
| String getAudioPath(String contentId) | |
| String getVideoPath(String contentId) | |
| I've probably done loads of things wrong here, but hey a) I'm not a Java programmer and b) IT WORKS! | |
| Cheers! | |
| Kosso | |
| Copyright : Kosso 2012. | |
| **/ | |
| package com.kosso.mediaquery; | |
| import org.appcelerator.kroll.KrollModule; | |
| import org.appcelerator.kroll.annotations.Kroll; | |
| import org.appcelerator.titanium.TiApplication; | |
| import org.appcelerator.kroll.common.Log; | |
| import org.appcelerator.kroll.common.TiConfig; | |
| import android.net.Uri; | |
| import android.provider.MediaStore; | |
| import android.database.Cursor; | |
| import android.app.Activity; | |
| import android.content.Context; | |
| import android.content.Intent; | |
| import android.content.ContentUris; | |
| import android.content.ContentResolver; | |
| @Kroll.module(name="Mediaquery", id="com.kosso.mediaquery") | |
| public class MediaqueryModule extends KrollModule | |
| { | |
| // Standard Debugging variables | |
| private static final String LCAT = "MediaqueryModule"; | |
| private static final boolean DBG = TiConfig.LOGD; | |
| // You can define constants with @Kroll.constant, for example: | |
| // @Kroll.constant public static final String EXTERNAL_NAME = value; | |
| public MediaqueryModule() { | |
| super("mediaquery"); | |
| } | |
| // Methods | |
| @Kroll.method | |
| public String getAudioPath(String contentId) { | |
| Uri theMediaUri = Uri.withAppendedPath(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, contentId); | |
| String[] projection = { MediaStore.Audio.Media.DATA }; | |
| // Do the query ... | |
| //Cursor mCur = getTiContext().getActivity().getContentResolver().query(theMediaUri, projection, null, null, null); | |
| // update | |
| Cursor mCur = getActivity().getContentResolver().query(theMediaUri, projection, null, null, null); | |
| Log.d(LCAT, "########## CALLING getAudioPath "); | |
| int column_index = mCur.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA); | |
| mCur.moveToFirst(); | |
| return mCur.getString(column_index); | |
| } | |
| @Kroll.method | |
| public String getVideoPath(String contentId) { | |
| Uri theMediaUri = Uri.withAppendedPath(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, contentId); | |
| String[] projection = { MediaStore.Video.Media.DATA }; | |
| // Do the query ... | |
| //Cursor mCur = getTiContext().getActivity().getContentResolver().query(theMediaUri, projection, null, null, null); | |
| // update | |
| Cursor mCur = getActivity().getContentResolver().query(theMediaUri, projection, null, null, null); | |
| Log.d(LCAT, "########## CALLING getVideoPath "); | |
| int column_index = mCur.getColumnIndexOrThrow(MediaStore.Video.Media.DATA); | |
| mCur.moveToFirst(); | |
| return mCur.getString(column_index); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment