create wav file, stock into a data storage: Content Provider

All your problems with Audio, Video and Images.

create wav file, stock into a data storage: Content Provider

Postby Dayn » Wed Aug 19, 2009 11:06 am

How can I take: "Create a wav file and stock this into a data storage
with Content Providers"

I try to use the same thing like the following exemple:

http://developer.android.com/intl/fr/gu ... ontent-p...

with a Bitmap:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import android.provider.Contacts.People;
  2.  
  3. import android.content.ContentResolver;
  4.  
  5. import android.content.ContentValues;
  6.  
  7.  
  8.  
  9. ContentValues values = new ContentValues();
  10.  
  11.  
  12.  
  13. // Add Abraham Lincoln to contacts and make him a favorite.
  14.  
  15. values.put(People.NAME, "Abraham Lincoln");
  16.  
  17. // 1 = the new contact is added to favorites
  18.  
  19. // 0 = the new contact is not added to favorites
  20.  
  21. values.put(People.STARRED, 1);
  22.  
  23.  
  24.  
  25. Uri uri = getContentResolver().insert(People.CONTENT_URI, values);
  26.  
  27.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Uri phoneUri = null;
  2.  
  3. Uri emailUri = null;
  4.  
  5.  
  6.  
  7. // Add a phone number for Abraham Lincoln.  Begin with the URI for
  8.  
  9. // the new record just returned by insert(); it ends with the _ID
  10.  
  11. // of the new record, so we don't have to add the ID ourselves.
  12.  
  13. // Then append the designation for the phone table to this URI,
  14.  
  15. // and use the resulting URI to insert the phone number.
  16.  
  17. phoneUri = Uri.withAppendedPath(uri, People.Phones.CONTENT_DIRECTORY);
  18.  
  19.  
  20.  
  21. values.clear();
  22.  
  23. values.put(People.Phones.TYPE, People.Phones.TYPE_MOBILE);
  24.  
  25. values.put(People.Phones.NUMBER, "1233214567");
  26.  
  27. getContentResolver().insert(phoneUri, values);
  28.  
  29.  
  30.  
  31. // Now add an email address in the same way.
  32.  
  33. emailUri = Uri.withAppendedPath(uri, People.ContactMethods.CONTENT_DIRECTORY);
  34.  
  35.  
  36.  
  37. values.clear();
  38.  
  39. // ContactMethods.KIND is used to distinguish different kinds of
  40.  
  41. // contact methods, such as email, IM, etc.
  42.  
  43. values.put(People.ContactMethods.KIND, Contacts.KIND_EMAIL);
  44.  
  45. values.put(People.ContactMethods.DATA, "test@example.com");
  46.  
  47. values.put(People.ContactMethods.TYPE, People.ContactMethods.TYPE_HOME);
  48.  
  49. getContentResolver().insert(emailUri, values);  
  50.  
  51.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


So I think is too similar but I'm really lose !!

Firstly I don't find how to create my File with my byte[].

I try to make that:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  byte[] decoded = Base64.decode( tabMsg[0].getMsgBase64() );
  2.  
  3.  
  4.  
  5.             ContentValues values = new ContentValues();
  6.  
  7.             values.put(Media.DISPLAY_NAME, "Voicemail1");
  8.  
  9.             values.put(Media.MIME_TYPE, "Audio/wav");
  10.  
  11.  
  12.  
  13.             Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI,
  14.  
  15. values);
  16.  
  17.  
  18.  
  19.             File m_wav = new File(uri.getEncodedPath(), "voicemail1.wav");
  20.  
  21.  
  22.  
  23.             try
  24.  
  25.             {
  26.  
  27.                 OutputStream outStream = getContentResolver().openOutputStream
  28.  
  29. (uri);
  30.  
  31.                 outStream.write(decoded);
  32.  
  33.                 outStream.close();
  34.  
  35.             }
  36.  
  37.             catch (Exception e)
  38.  
  39.             {
  40.  
  41.                 Log.e(TAG, "Exception while writing audio", e);
  42.  
  43.             }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


Could you light me, please ??
What are you thinking about my little code and how can I
continuous ???

It's very hard to use the better arguments or parametres with:
values.put(...) and with : getContentResolver().insert(..)

Maybe I have to create my own Content Providers but I think is too
compicated !

Dayn
User avatar
Dayn
Developer
Developer
 
Posts: 31
Joined: Thu Jul 09, 2009 10:45 am
Location: Paris and Dijon

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Google [Bot] and 15 guests