diff options
author | Ben Komalo <benkomalo@google.com> | 2010-12-23 15:25:58 -0500 |
---|---|---|
committer | Ben Komalo <benkomalo@google.com> | 2010-12-23 15:27:11 -0500 |
commit | c27e0b7e8c87db872bf3fd7ceda169ad725be33c (patch) | |
tree | 85c4c035a2a7aff657e5cb14c1b8fe630b92a3a2 /src | |
parent | a2c45606f832f8eb4cac93a238c178e361d2c2df (diff) | |
download | android_packages_apps_Tag-c27e0b7e8c87db872bf3fd7ceda169ad725be33c.tar.gz android_packages_apps_Tag-c27e0b7e8c87db872bf3fd7ceda169ad725be33c.tar.bz2 android_packages_apps_Tag-c27e0b7e8c87db872bf3fd7ceda169ad725be33c.zip |
Fix notification sound for tag discovery.
The create() convenience function calls
prepare(), which disallows further modification
to the MediaPlayer.
Note: the system (instead of the app)
may play the notification in the future,
depending on changes we make to the workflow
Change-Id: Ia0430930ccba30d21e79b510c449b63dcb01fe0e
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/apps/tag/TagViewer.java | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/src/com/android/apps/tag/TagViewer.java b/src/com/android/apps/tag/TagViewer.java index af44f4b..e0af182 100644 --- a/src/com/android/apps/tag/TagViewer.java +++ b/src/com/android/apps/tag/TagViewer.java @@ -18,7 +18,6 @@ package com.android.apps.tag; import com.android.apps.tag.message.NdefMessageParser; import com.android.apps.tag.message.ParsedNdefMessage; -import com.android.apps.tag.provider.TagContract; import com.android.apps.tag.provider.TagContract.NdefMessages; import com.android.apps.tag.record.ParsedNdefRecord; @@ -30,6 +29,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; +import android.content.res.AssetFileDescriptor; import android.database.Cursor; import android.media.AudioManager; import android.media.MediaPlayer; @@ -60,6 +60,7 @@ import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; +import java.io.IOException; import java.util.List; /** @@ -223,15 +224,31 @@ public class TagViewer extends Activity implements OnClickListener { mStar.setEnabled(true); // Play notification. - MediaPlayer player = MediaPlayer.create(this, R.raw.discovered_tag_notification); - player.setAudioStreamType(AudioManager.STREAM_NOTIFICATION); - player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { - @Override - public void onCompletion(MediaPlayer mp) { - mp.release(); + try { + AssetFileDescriptor afd = getResources().openRawResourceFd( + R.raw.discovered_tag_notification); + if (afd != null) { + MediaPlayer player = new MediaPlayer(); + player.setDataSource( + afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); + afd.close(); + player.setAudioStreamType(AudioManager.STREAM_NOTIFICATION); + player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { + @Override + public void onCompletion(MediaPlayer mp) { + mp.release(); + } + }); + player.prepare(); + player.start(); } - }); - player.start(); + } catch (IOException ex) { + Log.d(TAG, "Unable to play sound for tag discovery", ex); + } catch (IllegalArgumentException ex) { + Log.d(TAG, "Unable to play sound for tag discovery", ex); + } catch (SecurityException ex) { + Log.d(TAG, "Unable to play sound for tag discovery", ex); + } } else if (Intent.ACTION_VIEW.equals(action)) { // Setup the views |