generate Media Player - Android Media

Android examples for Media:Media Player

Description

generate Media Player

Demo Code


//package com.java2s;
import java.io.IOException;

import android.content.Context;

import android.media.MediaPlayer;
import android.net.Uri;

public class Main {
    public final static MediaPlayer generateMediaPlayer(Context context,
            int stream, int resId) {
        MediaPlayer mp = new MediaPlayer();
        mp.setAudioStreamType(stream);//from w w  w  . j  a  v  a2 s .  co  m
        try {
            mp.setDataSource(
                    context,
                    Uri.parse("android.resource://nl.versteeg.wakecube/"
                            + resId));
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return mp;
    }
}

Related Tutorials