MainActivity.java
<code>
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
Uri uri = Uri.parse("https://freetestdata.com/wp-content/ uploads/2021/09/Free_Test_ Data_100KB_OGG.ogg");
MediaPlayer player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource(this,uri);
player.prepare();
player.start();
} catch(Exception e) {
System.out.println(e.toString());
}
}
}
Android Manifeste:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_ STATE" />
https://developer.android.com/guide/topics/media/platform/mediaplayer#java
Comments
Post a Comment