开发者

problem to play sound from URL [closed]

开发者 https://www.devze.com 2023-03-27 09:19 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

i want to play a sound from url :: but i cant able to do that , i have implement this code

package com.TestAudio;


import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;

public class TestAudio extends Activity {
    /** Called when the activity is first created. */
    private MediaPlayer xmPlayer2, xmPlayer3, xmPlayer4, xmPlayer5, xmPlayer6,
    xmPlayer7,xmPlayer8,xmPlayer9,xmPlayer10,xmPlayer11;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);




        prepareforaudio(xmPlayer2,"bike_route.mp3");
        prepareforaudio(xmPlayer3,"closed.mp3");
        prepareforaudio(xmPlayer4,"exit.mp3");
        prepareforaudio(xmPlayer5,"no_parking.mp3");
        prepareforaudio(xmPlayer6,"one_way.mp3");
        prepareforaudio(xmPlayer7,"phone.mp3");
        prepareforaudio(xmPlayer8,"rail_road_crossing.mp3");
        prepareforaudio(xmPlayer9,"sale.mp3");
        prepareforaudio(xmPlayer10,"stop.mp3");
        prepareforaudio(xmPlayer11,"turn_off_tap.mp3");



    }
    public void prepareforaudio(MediaPlayer player,String music1)
    {
        try
        {
        player.开发者_C百科setAudioStreamType(AudioManager.STREAM_MUSIC);
        player.setDataSource("http://xyz/MRESC/images/test/"+music1);
        player.prepare(); 
        player.start();
        }catch (Exception e) {
            // TODO: handle exception
        }
    }
}

Permission :

 <uses-permission android:name="android.permission.INTERNET"></uses-permission>


initialize your media player object as MediaPlayer mplayer=new MediaPlayer();

0

精彩评论

暂无评论...
验证码 换一张
取 消