Browse Source

Ajout MediaPlayer class

pull/1/head
Samuel Vermeulen 6 months ago
parent
commit
905edce2b8
  1. 17
      .idea/deploymentTargetDropDown.xml
  2. 2
      .idea/misc.xml
  3. 31
      app/src/main/java/fr/svpro/radiomercure/MainActivity.java
  4. 27
      app/src/main/java/fr/svpro/radiomercure/MediaWebView.java
  5. 5
      app/src/main/res/layout/activity_main.xml
  6. 7
      app/src/main/res/menu/option.xml
  7. 1
      app/src/main/res/values/strings.xml

17
.idea/deploymentTargetDropDown.xml

@ -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

@ -5,7 +5,7 @@
<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/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" />
</map>
</option>

31
app/src/main/java/fr/svpro/radiomercure/MainActivity.java

@ -6,16 +6,22 @@ import android.app.Dialog;
import android.app.DownloadManager;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
import android.webkit.CookieManager;
import android.webkit.JavascriptInterface;
import android.webkit.URLUtil;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
import android.widget.Toast;
@ -23,6 +29,8 @@ import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
private static final int WRITE_EXTERNAL_STORAGE_RC = 100;
@ -39,16 +47,17 @@ public class MainActivity extends AppCompatActivity {
versionName = BuildConfig.VERSION_NAME;
}
@SuppressLint("SetJavaScriptEnabled")
@SuppressLint({"SetJavaScriptEnabled", "WrongViewCast", "JavascriptInterface"})
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//-------------A revoir-----------//
// getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
//--------------------------------//
web = findViewById(R.id.wv);
web.setWebViewClient(new WebViewClient());
web.getSettings().setUserAgentString("Mozilla/5.0 "+ getApplicationInfo().packageName);
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setAllowFileAccess(true);
@ -62,11 +71,12 @@ public class MainActivity extends AppCompatActivity {
web.getSettings().setUseWideViewPort(true);
web.getSettings().setLoadWithOverviewMode(true);
web.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
//Log.w("AGENT", web.getSettings().getUserAgentString());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
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) -> {
MainActivity.this.url = url;
@ -165,6 +175,21 @@ public class MainActivity extends AppCompatActivity {
startActivity(intent);
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:
return super.onOptionsItemSelected(item);
}

27
app/src/main/java/fr/svpro/radiomercure/MediaWebView.java

@ -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);
}
}

5
app/src/main/res/layout/activity_main.xml

@ -9,5 +9,8 @@
<WebView
android:id="@+id/wv"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent">
</WebView>
</androidx.constraintlayout.widget.ConstraintLayout>

7
app/src/main/res/menu/option.xml

@ -10,11 +10,18 @@
android:id="@+id/refresh"
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
android:id="@+id/tel"
android:icon="@android:drawable/stat_sys_phone_call"
android:title="@string/menu_phone"
app:showAsAction="ifRoom" />
<item
android:id="@+id/exit"
android:icon="@android:drawable/ic_lock_power_off"

1
app/src/main/res/values/strings.xml

@ -2,6 +2,7 @@
<string name="app_name">Radio Mercure</string>
<string name="menu_exit">Quitter</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_about">A Propos...</string>
<string name="dialog_close">Fermer</string>

Loading…
Cancel
Save