Ajout MediaPlayer class
This commit is contained in:
17
.idea/deploymentTargetDropDown.xml
generated
17
.idea/deploymentTargetDropDown.xml
generated
@@ -1,17 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="deploymentTargetDropDown">
|
|
||||||
<targetSelectedWithDropDown>
|
|
||||||
<Target>
|
|
||||||
<type value="QUICK_BOOT_TARGET" />
|
|
||||||
<deviceKey>
|
|
||||||
<Key>
|
|
||||||
<type value="VIRTUAL_DEVICE_PATH" />
|
|
||||||
<value value="C:\Users\samue\.android\avd\Nexus_6_API_29.avd" />
|
|
||||||
</Key>
|
|
||||||
</deviceKey>
|
|
||||||
</Target>
|
|
||||||
</targetSelectedWithDropDown>
|
|
||||||
<timeTargetWasSelectedWithDropDown value="2022-03-31T21:48:44.877184900Z" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -5,7 +5,7 @@
|
|||||||
<map>
|
<map>
|
||||||
<entry key="..\:/Users/samue/GIT/RadioMercure/app/src/main/res/drawable/ic_launcher_background.xml" value="0.2355" />
|
<entry key="..\:/Users/samue/GIT/RadioMercure/app/src/main/res/drawable/ic_launcher_background.xml" value="0.2355" />
|
||||||
<entry key="..\:/Users/samue/GIT/RadioMercure/app/src/main/res/layout/about_dialog.xml" value="0.2" />
|
<entry key="..\:/Users/samue/GIT/RadioMercure/app/src/main/res/layout/about_dialog.xml" value="0.2" />
|
||||||
<entry key="..\:/Users/samue/GIT/RadioMercure/app/src/main/res/layout/activity_main.xml" value="0.11402623612512613" />
|
<entry key="..\:/Users/samue/GIT/RadioMercure/app/src/main/res/layout/activity_main.xml" value="0.5" />
|
||||||
<entry key="..\:/Users/samue/GIT/RadioMercure/app/src/main/res/menu/option.xml" value="0.33" />
|
<entry key="..\:/Users/samue/GIT/RadioMercure/app/src/main/res/menu/option.xml" value="0.33" />
|
||||||
</map>
|
</map>
|
||||||
</option>
|
</option>
|
||||||
|
|||||||
@@ -6,16 +6,22 @@ import android.app.Dialog;
|
|||||||
import android.app.DownloadManager;
|
import android.app.DownloadManager;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.media.MediaPlayer;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.view.WindowManager;
|
||||||
import android.webkit.CookieManager;
|
import android.webkit.CookieManager;
|
||||||
|
import android.webkit.JavascriptInterface;
|
||||||
import android.webkit.URLUtil;
|
import android.webkit.URLUtil;
|
||||||
|
import android.webkit.WebChromeClient;
|
||||||
import android.webkit.WebSettings;
|
import android.webkit.WebSettings;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
import android.webkit.WebViewClient;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@@ -23,6 +29,8 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private static final int WRITE_EXTERNAL_STORAGE_RC = 100;
|
private static final int WRITE_EXTERNAL_STORAGE_RC = 100;
|
||||||
@@ -39,16 +47,17 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
versionName = BuildConfig.VERSION_NAME;
|
versionName = BuildConfig.VERSION_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("SetJavaScriptEnabled")
|
@SuppressLint({"SetJavaScriptEnabled", "WrongViewCast", "JavascriptInterface"})
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
//-------------A revoir-----------//
|
//-------------A revoir-----------//
|
||||||
// getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
//--------------------------------//
|
//--------------------------------//
|
||||||
|
|
||||||
web = findViewById(R.id.wv);
|
web = findViewById(R.id.wv);
|
||||||
|
web.setWebViewClient(new WebViewClient());
|
||||||
web.getSettings().setUserAgentString("Mozilla/5.0 "+ getApplicationInfo().packageName);
|
web.getSettings().setUserAgentString("Mozilla/5.0 "+ getApplicationInfo().packageName);
|
||||||
web.getSettings().setJavaScriptEnabled(true);
|
web.getSettings().setJavaScriptEnabled(true);
|
||||||
web.getSettings().setAllowFileAccess(true);
|
web.getSettings().setAllowFileAccess(true);
|
||||||
@@ -62,11 +71,12 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
web.getSettings().setUseWideViewPort(true);
|
web.getSettings().setUseWideViewPort(true);
|
||||||
web.getSettings().setLoadWithOverviewMode(true);
|
web.getSettings().setLoadWithOverviewMode(true);
|
||||||
web.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
|
web.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
|
||||||
|
|
||||||
//Log.w("AGENT", web.getSettings().getUserAgentString());
|
//Log.w("AGENT", web.getSettings().getUserAgentString());
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||||
web.getSettings().setAllowFileAccessFromFileURLs(true);
|
web.getSettings().setAllowFileAccessFromFileURLs(true);
|
||||||
}
|
}
|
||||||
web.loadUrl("https://www.radiomercure.fr");
|
web.loadUrl("https://www.radiomercure.fr/?playerbar-pageinicial");
|
||||||
|
|
||||||
web.setDownloadListener((url, userAgent, contentDisposition, mimeType, contentLength) -> {
|
web.setDownloadListener((url, userAgent, contentDisposition, mimeType, contentLength) -> {
|
||||||
MainActivity.this.url = url;
|
MainActivity.this.url = url;
|
||||||
@@ -165,6 +175,21 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
case R.id.live:
|
||||||
|
MediaPlayer mediaPlayer = new MediaPlayer();
|
||||||
|
try {
|
||||||
|
mediaPlayer.setDataSource("https://live.radiomercure.fr/on-air/live");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
mediaPlayer.prepare();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
mediaPlayer.start();
|
||||||
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
package fr.svpro.radiomercure;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.util.AttributeSet;
|
|
||||||
import android.webkit.WebView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
public class MediaWebView extends WebView {
|
|
||||||
|
|
||||||
public MediaWebView(@NonNull Context context) {
|
|
||||||
super(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MediaWebView(@NonNull Context context, @Nullable AttributeSet attrs) {
|
|
||||||
super(context, attrs);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MediaWebView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
|
||||||
super(context, attrs, defStyleAttr);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MediaWebView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,5 +9,8 @@
|
|||||||
<WebView
|
<WebView
|
||||||
android:id="@+id/wv"
|
android:id="@+id/wv"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
</WebView>
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -10,11 +10,18 @@
|
|||||||
android:id="@+id/refresh"
|
android:id="@+id/refresh"
|
||||||
android:title="@string/menu_reload" />
|
android:title="@string/menu_reload" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/live"
|
||||||
|
android:icon="@android:drawable/ic_media_play"
|
||||||
|
app:showAsAction="ifRoom"
|
||||||
|
android:title="@string/menu_live" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/tel"
|
android:id="@+id/tel"
|
||||||
android:icon="@android:drawable/stat_sys_phone_call"
|
android:icon="@android:drawable/stat_sys_phone_call"
|
||||||
android:title="@string/menu_phone"
|
android:title="@string/menu_phone"
|
||||||
app:showAsAction="ifRoom" />
|
app:showAsAction="ifRoom" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/exit"
|
android:id="@+id/exit"
|
||||||
android:icon="@android:drawable/ic_lock_power_off"
|
android:icon="@android:drawable/ic_lock_power_off"
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
<string name="app_name">Radio Mercure</string>
|
<string name="app_name">Radio Mercure</string>
|
||||||
<string name="menu_exit">Quitter</string>
|
<string name="menu_exit">Quitter</string>
|
||||||
<string name="menu_phone">Appeler la Radio</string>
|
<string name="menu_phone">Appeler la Radio</string>
|
||||||
|
<string name="menu_live">Ecouter en direct</string>
|
||||||
<string name="menu_reload">Relancer...</string>
|
<string name="menu_reload">Relancer...</string>
|
||||||
<string name="menu_about">A Propos...</string>
|
<string name="menu_about">A Propos...</string>
|
||||||
<string name="dialog_close">Fermer</string>
|
<string name="dialog_close">Fermer</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user