Example usage for android.media AudioManager STREAM_MUSIC

List of usage examples for android.media AudioManager STREAM_MUSIC

Introduction

In this page you can find the example usage for android.media AudioManager STREAM_MUSIC.

Prototype

int STREAM_MUSIC

To view the source code for android.media AudioManager STREAM_MUSIC.

Click Source Link

Document

Used to identify the volume of audio streams for music playback

Usage

From source file:com.rainmakerlabs.bleepsample.BleepService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.d(TAG, "onStartCommand");
    String actionName = intent.getStringExtra("actionName");
    if (intent == null || intent.getExtras() == null) {//just removing these checks
    } else if (actionName.equalsIgnoreCase(BLEepService.INTENT_BLEEP_PROCESS)
            && intent.getExtras().containsKey(BLEepService.INTENT_BLEEP_PASSED_LIST)) {
        ArrayList<Bleep> bleeps = (ArrayList<Bleep>) intent.getExtras()
                .getSerializable(BLEepService.INTENT_BLEEP_PASSED_LIST);
        for (final Bleep bleep : bleeps) {
            String msgType = bleep.getType();
            String atts = bleep.getAtts();
            try {
                JSONObject objMsg = new JSONObject(atts);
                //thisBleepService.addExtraLog(bleep, "FEEDBACK", "good");//use this when you want to send a custom log to BMS. for instance, you could display a feedback dialog, and ask users to give a rating, and BMS will help you collate the information. put this where necessary, it's just here for example
                Log.d(TAG, "Message Received of Type: " + msgType);
                if (msgType.equalsIgnoreCase("image")) {
                    final String strImgUrl = objMsg.optString(APIKeyDefineCommand.MSG_IMG);
                    final String adAspect = objMsg.optString(APIKeyDefineCommand.MSG_IMGASP);
                    String strImgMsgTemp = objMsg.optString(APIKeyDefineCommand.MSG_NOTIF);
                    //putting the default message above would only work for missing key, not in case of empty string. empty string will prevent the notification, so fix below
                    if (strImgMsgTemp.equalsIgnoreCase(""))
                        strImgMsgTemp = "No Message";
                    final String strImgMsg = strImgMsgTemp;
                    if (checkIfClosed()) {
                        if (oldcodeon)
                            localNotification("", strImgMsg, 0);
                        continue;
                    }/*from  ww w. j a va2 s  .  co m*/
                    if (MainActivity.adlib.get(strImgMsg) == null && !strImgMsg.equalsIgnoreCase("No Message"))
                        Log.d(TAG, "image url start download for key: " + strImgMsg + ", url = " + strImgUrl);
                    else {
                        Log.d(TAG, "Image exists, or no message, not downloading..., key: " + strImgMsg);
                        continue;
                    }

                    if (strImgMsg.equalsIgnoreCase("$28")) {
                        Log.d("Portal", "Image exists, loading from cache");
                        imgShow(BitmapFactory.decodeResource(getResources(), R.drawable.singtel), strImgMsg);
                        continue;
                    } else if (strImgMsg.equalsIgnoreCase("$4.50")) {
                        Log.d("Portal", "Heineken Image exists, loading from cache");
                        imgShow(BitmapFactory.decodeResource(getResources(), R.drawable.heineken), strImgMsg);
                        continue;
                    }

                    ShutterbugManager.getSharedImageManager(BleepActivity.currentBleepActivity)
                            .download(strImgUrl, new ShutterbugManagerListener() {
                                @Override
                                public void onImageSuccess(ShutterbugManager imageManager, Bitmap bitmap,
                                        String url) {
                                    Log.d(TAG, "image url end download " + strImgUrl);
                                    if (strImgUrl.equalsIgnoreCase(AdDialog.getCurrentAdUrl()))
                                        return;
                                    if (AdDialog.howManyAdDialogsShowing == 1) {
                                        AdDialog.closeOnlyAdDialog();
                                    }
                                    final Bitmap bitmap2 = bitmap;

                                    imgShow(bitmap, strImgMsg);

                                    if (oldcodeon) {
                                        BleepActivity.currentBleepActivity.runOnUiThread(new Runnable() {
                                            public void run() {
                                                if (BleepActivity.isBackground)
                                                    localNotification("", strImgMsg, 0);
                                                AdDialog.showAdsDialog(BleepActivity.currentBleepActivity,
                                                        bitmap2, strImgUrl, adAspect);
                                            }
                                        });
                                    }
                                }

                                @Override
                                public void onImageFailure(ShutterbugManager imageManager, String url) {
                                    thisBleepService.eraseTriggerLog(bleep);//to cancel trigger log when trigger is cancelled
                                }
                            });
                } else if (oldcodeon == false) {//don't run anything else
                } else if (msgType.equalsIgnoreCase("alert") && oldcodeon) {

                    // show alert message
                    if (checkIfClosed() || BleepActivity.isBackground) {
                        localNotification(objMsg.optString(APIKeyDefineCommand.MSG_TITLE),
                                objMsg.optString(APIKeyDefineCommand.MSG_CONTENT), 1);
                    } else {
                        showAlert(objMsg.optString(APIKeyDefineCommand.MSG_TITLE),
                                objMsg.optString(APIKeyDefineCommand.MSG_CONTENT));
                    }
                } else if (msgType.equalsIgnoreCase("launch")) {
                    String intentAction = objMsg.optString(APIKeyDefineCommand.MSG_APP_INTENT);
                    String intentUri = objMsg.optString(APIKeyDefineCommand.MSG_APP_URI);
                    String intentType = "";
                    String intentExtras = objMsg.optString(APIKeyDefineCommand.MSG_APP_EXTRAS);
                    String cfmMsg = objMsg.optString(APIKeyDefineCommand.MSG_APP_CFM);
                    String failMsg = objMsg.optString(APIKeyDefineCommand.MSG_APP_FAIL);
                    processTypeLaunch(intentAction, intentUri, intentType, intentExtras, cfmMsg, failMsg, 2);
                } else if (msgType.equalsIgnoreCase("url")) {
                    String intentAction = Intent.ACTION_VIEW;
                    String intentUri = objMsg.optString(APIKeyDefineCommand.MSG_MEDIA_URL);
                    String intentType = "";
                    String intentExtras = "";
                    String cfmMsg = objMsg.optString(APIKeyDefineCommand.MSG_APP_CFM);
                    String failMsg = objMsg.optString(APIKeyDefineCommand.MSG_APP_FAIL);
                    processTypeLaunch(intentAction, intentUri, intentType, intentExtras, cfmMsg, failMsg, 3);
                } else if (msgType.equalsIgnoreCase("webview")) {
                    String intentAction = Intent.ACTION_VIEW;
                    String intentUri = objMsg.optString(APIKeyDefineCommand.MSG_MEDIA_URL);
                    String intentType = "";
                    String intentExtras = "";
                    String cfmMsg = objMsg.optString(APIKeyDefineCommand.MSG_NOTIF);
                    if (cfmMsg.equalsIgnoreCase(""))
                        cfmMsg = "View webpage?";
                    String failMsg = "";
                    processTypeLaunch(intentAction, intentUri, intentType, intentExtras, cfmMsg, failMsg, 4);
                } else if (msgType.equalsIgnoreCase("video")) {
                    String strVidUrl = objMsg.optString(APIKeyDefineCommand.MSG_MEDIA_URL);
                    Intent vidIntent = new Intent(this, VideoActivity.class);
                    vidIntent.putExtra("url", strVidUrl);
                    String notifMsg = objMsg.optString(APIKeyDefineCommand.MSG_NOTIF);
                    if (notifMsg.equalsIgnoreCase(""))
                        notifMsg = "Play video?";
                    if (!checkIfClosed() && BleepActivity.isVideoActivityOpen) {
                        thisBleepService.eraseTriggerLog(bleep);//to cancel trigger log when trigger is cancelled
                    } else if (checkIfClosed() || BleepActivity.isBackground) {
                        vidIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        vidIntent.setAction(Intent.ACTION_MAIN);
                        vidIntent.addCategory(Intent.CATEGORY_LAUNCHER);
                        localNotification("", notifMsg, vidIntent, "Video opening failed!", 5);
                    } else {
                        BleepActivity.currentBleepActivity.startActivity(vidIntent);
                    }
                } else if (msgType.equalsIgnoreCase("audio")) {
                    String url = objMsg.optString(APIKeyDefineCommand.MSG_MEDIA_URL);
                    mediaPlayer = new MediaPlayer();
                    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                    try {
                        mediaPlayer.setDataSource(url);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    mediaPlayer.prepareAsync();
                    mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                        @Override
                        public void onPrepared(MediaPlayer mp) {
                            mp.start();
                        }
                    });
                    mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
                        @Override
                        public boolean onError(MediaPlayer mp, int what, int extra) {
                            return false;
                        }
                    });
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        //      } else if (actionName.equalsIgnoreCase(BLEepService.INTENT_BLEEP_EXIT) && intent.getExtras().containsKey(BLEepService.INTENT_MSG_NAME)) {
        //         HashMap<String, Object> beaconOutInfo = (HashMap<String, Object>)intent.getSerializableExtra(BLEepService.INTENT_MSG_NAME);   
        //         //Log.d("debug!","debug! this beacon just went out "+beaconOutInfo.get("uuid")+" "+beaconOutInfo.get("major")+" "+beaconOutInfo.get("minor")+" "+beaconOutInfo.get("tag")+" "+beaconOutInfo.get("beaconID"));
    } else if (actionName.equalsIgnoreCase(BLEepService.INTENT_BLEEP_STATE)
            && intent.getExtras().containsKey(BLEepService.INTENT_MSG_NAME)) {
        int beaconState = intent.getIntExtra(BLEepService.INTENT_MSG_NAME, 99);
    }

    return START_NOT_STICKY;
}

From source file:org.kontalk.ui.AudioDialog.java

void playAudio() {
    mProgressBar.setClickable(true);/*w  w  w  .j a v  a2 s .c om*/
    try {
        MediaPlayer player = mData.getPlayer();
        player.setAudioStreamType(AudioManager.STREAM_MUSIC);
        player.setDataSource(mFile.getAbsolutePath());
        player.prepare();
    } catch (IOException e) {
        Log.e(TAG, "error reading from external storage", e);
        new MaterialDialog.Builder(getContext()).content(R.string.err_playing_sdcard)
                .positiveText(android.R.string.ok).show();
    } catch (Exception e) {
        Log.e(TAG, "error playing audio", e);
    }
    setupForPlaying();
    animate(mProgressBar, null, 0, MAX_PROGRESS, mData.getPlayer().getDuration());
    resumeAudio();
}

From source file:com.fanfou.app.opensource.HomePage.java

private void initSoundManager() {
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    SoundManager.getInstance();
    SoundManager.initSounds(this);
    SoundManager.loadSounds();
}

From source file:com.marvin.rocklock.RockLockActivity.java

/**
 * Pick up back button and volume up and down
 *///from  w w w  .  ja  va 2  s .c  o m
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
        mPlayer.togglePlayPause();
        return true;
    case KeyEvent.KEYCODE_MEDIA_NEXT:
        mPlayer.nextTrack(false);
        return true;
    case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
        mPlayer.prevTrack(false);
        return true;
    case KeyEvent.KEYCODE_VOLUME_UP:
        mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE,
                AudioManager.FLAG_PLAY_SOUND);
        return true;
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER,
                AudioManager.FLAG_PLAY_SOUND);
        return true;
    case KeyEvent.KEYCODE_BACK:
        onBackPressed();
        return true;
    default:
        return super.onKeyDown(keyCode, event);
    }
}

From source file:com.google.fpl.voltair.VoltAirActivity.java

/**
 * @brief Called to process (and possibly intercept) key events.
 * @param event @c KeyEvent to handle// w w  w  .ja v a 2  s  .  com
 * @returns @c true if @p event was handled
 */
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        // Since QtActivity does not handle volume (throwing the events on the floor) and we
        // cannot call super.super, we must handle managing of the volume here
        // TODO: Figure out how to get the volume Ui slide to show up without permanently
        // breaking immersive mode.
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_VOLUME_UP:
            mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE,
                    0 /* No flags */);
            break;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER,
                    0 /* No flags */);
            break;
        }
    }

    // QtActivity (i.e. super) will convert all key events to QKeyEvents and *always* return
    // true saying it accepted the event -- even on Gamepad key events it doesn't understand.
    // This is annoying, and unfortunately means that we must always let controllers take a look
    // at the event even if QtActivity understood it and accepted it for use (e.g. in the UI).
    // However, we must be careful with events that are successfully translated (e.g. Keyboard
    // key events) so as to not spawn two separate controllers (one here with the Android
    // KeyEvent, and the other one in "InputArea" with the translated QKeyEvent).
    if (isGamepadEvent(event)) {
        if (onGamepadKeyEvent(event)) {
            return true;
        }
    } else if (isTouchNavigationEvent(event)) {
        if (onTouchNavigationKeyEvent(event)) {
            return true;
        }
    } else if (isKeyboardEvent(event)) {
        if (onKeyboardKeyEvent(event)) {
            return true;
        }
    }
    return super.dispatchKeyEvent(event);
}

From source file:fm.feed.android.playersdk.view.PlayerView.java

private void initializeView() {
    RelativeLayout rootView = (RelativeLayout) inflate(getContext(), R.layout.view_player, this);
    mTitle = (TextView) rootView.findViewById(R.id.pu_title);
    mArtist = (TextView) rootView.findViewById(R.id.pu_artist);
    mAlbum = (TextView) rootView.findViewById(R.id.pu_album);
    mPrefix = (TextView) rootView.findViewById(R.id.pu_prefix);
    mSuffix = (TextView) rootView.findViewById(R.id.pu_suffix);
    mProgressBar = (ProgressBar) rootView.findViewById(R.id.pu_progress);

    LinearLayout topContainer = (LinearLayout) rootView.findViewById(R.id.pu_top_icons);
    LinearLayout bottomContainer = (LinearLayout) rootView.findViewById(R.id.pu_bottom_icons);

    // We need to create the SVGImageView instances and add them programmatically.
    mDislike = newSvgImage(1, ImageView.ScaleType.FIT_START);
    mLike = newSvgImage(2, ImageView.ScaleType.FIT_CENTER);
    mPlayPause = newSvgImage(2, ImageView.ScaleType.FIT_CENTER);
    mSkip = newSvgImage(1, ImageView.ScaleType.FIT_END);
    mVolume = newSvgImage(1, ImageView.ScaleType.FIT_START);
    mShare = newSvgImage(1, ImageView.ScaleType.FIT_END);

    // Set the SVG resource to the SVGImageView
    setSvgResource(mDislike, R.drawable.ic_thumbdown_faded, R.string.accessibility_dislike);
    setSvgResource(mLike, R.drawable.ic_thumbup_faded, R.string.accessibility_like);
    setSvgResource(mPlayPause, R.drawable.ic_play_faded, R.string.accessibility_play);
    setSvgResource(mSkip, R.drawable.ic_skip_disabled, R.string.accessibility_skip_disabled);
    setSvgResource(mVolume, R.drawable.ic_speakerhigh_faded, R.string.accessibility_volume_muted);
    setSvgResource(mShare, R.drawable.ic_share_faded, R.string.accessibility_share);

    // Add SVGImageViews to the layout.
    topContainer.addView(mDislike);//from   w w w. j a v a 2s  .  com
    topContainer.addView(mLike);
    topContainer.addView(mPlayPause);
    topContainer.addView(mSkip);
    bottomContainer.addView(mVolume);
    bottomContainer.addView(mShare);

    mDislike.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!mPlayer.hasPlay()) {
                return;
            }

            Play.LikeState likeState = mPlayer.getPlay().getLikeState();
            switch (likeState) {
            case NONE:
                setSvgResource(mDislike, R.drawable.ic_thumbdown_normal, R.string.accessibility_disliked);
                mPlayer.dislike();
                break;
            case LIKED:
                setSvgResource(mLike, R.drawable.ic_thumbup_faded, R.string.accessibility_like);
                mPlayer.unlike();
                break;
            case DISLIKED:
                // Do nothing
                break;
            }
        }
    });

    mLike.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!mPlayer.hasPlay()) {
                return;
            }

            Play.LikeState likeState = mPlayer.getPlay().getLikeState();
            switch (likeState) {
            case NONE:
                setSvgResource(mLike, R.drawable.ic_thumbup_normal, R.string.accessibility_liked);
                mPlayer.like();
                break;
            case LIKED:
                // Do nothing
                break;
            case DISLIKED:
                setSvgResource(mDislike, R.drawable.ic_thumbdown_faded, R.string.accessibility_unlike);
                setSvgResource(mLike, R.drawable.ic_thumbup_normal, R.string.accessibility_liked);
                mPlayer.like();
                break;
            }
        }
    });
    mPlayPause.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mPlayer.getState() == PlayInfo.State.PLAYING) {
                mPlayer.pause();
            } else {
                mPlayer.play();
            }
        }
    });
    mSkip.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mPlayer.isSkippable()) {
                setSvgResource(mSkip, R.drawable.ic_skip_normal, R.string.accessibility_skipping);
                mPlayer.skip();
            }
        }
    });
    mShare.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mPlayer == null || !mPlayer.hasPlay()) {
                Log.i(TAG, "Cannot share if not playing");
                return;
            }

            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

            String subject = mShareSubject;
            String body = mShareBody;
            if (subject == null) {
                subject = getContext().getString(R.string.share_subject_template);
            }
            if (body == null) {
                Play play = mPlayer.getPlay();
                String title = play.getAudioFile().getTrack().getTitle();
                String artist = play.getAudioFile().getArtist().getName();
                String album = play.getAudioFile().getRelease().getTitle();

                body = getContext().getString(R.string.share_body_template, title, artist, album);
            }

            // Add data to the intent, the receiving app will decide what to do with it.
            intent.putExtra(Intent.EXTRA_SUBJECT, subject);
            intent.putExtra(Intent.EXTRA_TEXT, body);

            getContext()
                    .startActivity(Intent.createChooser(intent, getContext().getString(R.string.share_via)));
        }
    });

    mVolume.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            AudioManager am = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
            int volume = mAudioSettingsContentObserver.getCurrentVolume();
            am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, AudioManager.FLAG_SHOW_UI);
        }
    });

    updateSpeakerUI();
}

From source file:dk.nota.lyt.libvlc.PlaybackService.java

private void changeAudioFocus(boolean acquire) {
    final AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
    if (am == null)
        return;/*from w w  w . j  a v a 2s.  c om*/

    if (acquire) {
        if (!mHasAudioFocus) {
            final int result = am.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC,
                    AudioManager.AUDIOFOCUS_GAIN);
            if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
                am.setParameters("bgm_state=true");
                mHasAudioFocus = true;
            }
        }
    } else {
        if (mHasAudioFocus) {
            final int result = am.abandonAudioFocus(mAudioFocusListener);
            am.setParameters("bgm_state=false");
            mHasAudioFocus = false;
        }
    }
}

From source file:com.android.msahakyan.fma.fragment.TrackDetailFragment.java

private void mute(boolean mute) {
    AudioManager audioManager = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (!audioManager.isStreamMute(AudioManager.STREAM_MUSIC)) {
            audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,
                    mute ? AudioManager.ADJUST_MUTE : AudioManager.ADJUST_UNMUTE, 0);
        }// w w w .  j a  va  2 s  . c  om
    } else {
        audioManager.setStreamMute(AudioManager.STREAM_MUSIC, mute);
    }
}

From source file:im.vector.activity.CallViewActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // assume that the user cancels the call if it is ringing
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (!canCallBeResumed()) {
            if (null != mCall) {
                mCall.hangup("");
            }/*from w  w w  . j  a va 2s  . c o  m*/
        } else {
            saveCallView();
        }
    } else if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) || (keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {
        // this is a trick to reduce the ring volume :
        // when the call is ringing, the AudioManager.Mode switch to MODE_IN_COMMUNICATION
        // so the volume is the next call one whereas the user expects to reduce the ring volume.
        if ((null != mCall) && mCall.getCallState().equals(IMXCall.CALL_STATE_RINGING)) {
            AudioManager audioManager = (AudioManager) CallViewActivity.this
                    .getSystemService(Context.AUDIO_SERVICE);
            // IMXChrome call issue
            if (audioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION) {
                int musicVol = audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL)
                        * audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC)
                        / audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL);
                audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, musicVol, 0);
            }
        }
    }

    return super.onKeyDown(keyCode, event);
}

From source file:info.guardianproject.otr.app.im.app.MessageView.java

/**
 * @param mimeType//from www  .  java 2 s  . co m
 * @param body
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
protected void onClickMediaIcon(String mimeType, Uri mediaUri) {

    if (ChatFileStore.isVfsUri(mediaUri)) {
        if (mimeType.startsWith("image")) {
            Intent intent = new Intent(context, ImageViewActivity.class);
            intent.putExtra(ImageViewActivity.FILENAME, mediaUri.getPath());
            context.startActivity(intent);
            return;
        }
        if (mimeType.startsWith("audio")) {
            new AudioPlayer(getContext(), mediaUri.getPath(), mimeType).play();
            return;
        }
        return;
    } else {

        String body = convertMediaUriToPath(mediaUri);

        if (body == null)
            body = new File(mediaUri.getPath()).getAbsolutePath();

        if (mimeType.startsWith("audio")
                || (body.endsWith("3gp") || body.endsWith("3gpp") || body.endsWith("amr"))) {

            if (mMediaPlayer != null)
                mMediaPlayer.release();

            try {
                mMediaPlayer = new MediaPlayer();
                mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                mMediaPlayer.setDataSource(body);
                mMediaPlayer.prepare();
                mMediaPlayer.start();

                return;
            } catch (IOException e) {
                Log.e(ImApp.LOG_TAG, "error playing audio: " + body, e);
            }

        }

        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (Build.VERSION.SDK_INT >= 11)
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

        //set a general mime type not specific
        intent.setDataAndType(Uri.parse(body), mimeType);

        Context context = getContext().getApplicationContext();

        if (isIntentAvailable(context, intent)) {
            context.startActivity(intent);
        } else {
            Toast.makeText(getContext(), R.string.there_is_no_viewer_available_for_this_file_format,
                    Toast.LENGTH_LONG).show();
        }
    }
}