Play Audio via Intent - Android Media

Android examples for Media:Auto Player

Description

Play Audio via Intent

Demo Code


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

import android.content.Context;
import android.content.Intent;
import android.net.Uri;

public class Main {
    public static void PlayAudio(Context context, String audioPath) {

        Intent intent = new Intent();
        intent.setAction(android.content.Intent.ACTION_VIEW);
        File file = new File(audioPath.toString());
        intent.setDataAndType(Uri.fromFile(file), "audio/*");
        context.startActivity(intent);//from  w ww.  j ava 2s  .  c om
    }
}

Related Tutorials