بسم الله الرحمن الرحيم
أولا نفتح ملف xml
في ملف
Right Click on Drawable folder -> New -> Drawable Resource File , will create a XML file inside the Drawable folder.
ثم
Create a new XML file in the - الكود:
-
res/drawable/
directory (name it something like - الكود:
-
button_custom.xml
). Insert the following XML: <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_pressed"
android:state_pressed="true" />
<item android:drawable="@drawable/button_focused"
android:state_focused="true" />
<item android:drawable="@drawable/button_default" />
</selector>
This defines a single drawable resource, which will change its image based on the current state of the button.
- The first
- الكود:
-
<item>
defines the bitmap to use when the button is pressed (activated).
- The second
- الكود:
-
<item>
defines the bitmap to use when the button is focused (when the button is highlighted using the trackball or directional pad).
- The third
- الكود:
-
<item>
defines the bitmap to use when the button is in the default state (it's neither pressed nor focused).
[color:b3de=rgba(0, 0, 0, 0.682352941176471)]
الشرح بشكل اوضح على الرابطhttps://developer.android.com/guide/topics/ui/controls/button.html
http://www.android-examples.com/stream-play-online-audio-mp3-from-url-in-android/
How to Stream Play online audio mp3 from URL in android without downloading.
Code for Please add internet permission to your AndroidManifest.xml file. <uses-permission android:name="android.permission.INTERNET" />
Code for MainActivity.java file. package com.playonlineaudiomp3_android_examples.com;
import java.io.IOException;
import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
Button buttonStop,buttonStart ;
String AudioURL = "http://www.android-examples.com/wp-content/uploads/2016/04/Thunder-rumble.mp3";
MediaPlayer mediaplayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonStart = (Button)findViewById(R.id.button1);
buttonStop = (Button)findViewById(R.id.button2);
mediaplayer = new MediaPlayer();
mediaplayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
buttonStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
mediaplayer.setDataSource(AudioURL);
mediaplayer.prepare();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mediaplayer.start();
}
});
buttonStop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mediaplayer.stop();
}
});
}
}
Code for activity_main.xml layout file. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.playonlineaudiomp3_android_examples.com.MainActivity" >
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_centerHorizontal="true"
android:text="Stop Music From URL" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="157dp"
android:text="Start Music From URL" />
</RelativeLayout>
Screenshot: