Asem75 commited on
Commit
e7ebcc1
·
verified ·
1 Parent(s): 8b5fea0

Upload 4 files

Browse files
islamic_radio.css ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ .islamic-radio-section{display:block;width:100%}
2
+ .islamic-radio-tabs{display:flex;gap:.5rem;overflow-x:auto;padding:.5rem 0}
3
+ .islamic-radio-station{display:grid;grid-template-columns:1fr auto auto;gap:.6rem;align-items:center;padding:.8rem;border-radius:14px;margin-bottom:.5rem}
4
+ .islamic-radio-station.is-playing{outline:2px solid currentColor}
5
+ .islamic-radio-favorite{border:0;background:transparent;font-size:1.25rem;cursor:pointer}
6
+ .islamic-radio-player{position:sticky;bottom:0;z-index:20;display:grid;grid-template-columns:1fr auto auto;gap:.6rem;align-items:center;padding:.7rem;backdrop-filter:blur(12px)}
islamic_radio_manager.js ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Islamic Radio Manager — ساعة المسلم
3
+ قسم مستقل للإذاعات + تثبيت محلي + مشغل واحد + Media Session.
4
+ */
5
+
6
+ const ISLAMIC_RADIO_STORAGE_KEY = "muslim_clock_radio_favorites_v1";
7
+
8
+ export class IslamicRadioManager {
9
+ constructor(registry, options = {}) {
10
+ this.registry = registry || {stations: []};
11
+ this.audio = options.audio || document.createElement("audio");
12
+ this.audio.preload = "none";
13
+ this.audio.crossOrigin = "anonymous";
14
+ this.currentStation = null;
15
+ this.listeners = new Set();
16
+ this._loadFavorites();
17
+ }
18
+
19
+ _loadFavorites() {
20
+ try {
21
+ this.favorites = new Set(JSON.parse(
22
+ localStorage.getItem(ISLAMIC_RADIO_STORAGE_KEY) || "[]"
23
+ ));
24
+ } catch {
25
+ this.favorites = new Set();
26
+ }
27
+ }
28
+
29
+ _saveFavorites() {
30
+ localStorage.setItem(
31
+ ISLAMIC_RADIO_STORAGE_KEY,
32
+ JSON.stringify([...this.favorites])
33
+ );
34
+ }
35
+
36
+ onChange(fn) {
37
+ this.listeners.add(fn);
38
+ return () => this.listeners.delete(fn);
39
+ }
40
+
41
+ _emit(type, data = {}) {
42
+ for (const fn of this.listeners) {
43
+ try { fn({type, ...data}); } catch {}
44
+ }
45
+ }
46
+
47
+ list(category = null) {
48
+ return (this.registry.stations || [])
49
+ .filter(s => !category || s.category === category)
50
+ .map(s => ({...s, favorite: this.favorites.has(s.id)}))
51
+ .sort((a,b) => Number(b.favorite) - Number(a.favorite));
52
+ }
53
+
54
+ toggleFavorite(id) {
55
+ this.favorites.has(id)
56
+ ? this.favorites.delete(id)
57
+ : this.favorites.add(id);
58
+ this._saveFavorites();
59
+ this._emit("favorite", {id, favorite: this.favorites.has(id)});
60
+ return this.favorites.has(id);
61
+ }
62
+
63
+ getFavorites() {
64
+ return this.list().filter(s => s.favorite);
65
+ }
66
+
67
+ async play(id) {
68
+ const station = (this.registry.stations || []).find(s => s.id === id);
69
+ if (!station) throw new Error("Radio station not found");
70
+
71
+ if (!station.streamUrl) {
72
+ this._emit("externalFallback", {station});
73
+ if (station.officialUrl)
74
+ window.open(station.officialUrl, "_blank", "noopener");
75
+ return false;
76
+ }
77
+
78
+ await this.stop();
79
+ this.currentStation = station;
80
+ this.audio.src = station.streamUrl;
81
+ this.audio.loop = true;
82
+
83
+ this._setMediaSession(station);
84
+
85
+ try {
86
+ await this.audio.play();
87
+ this._emit("playing", {station});
88
+ return true;
89
+ } catch (error) {
90
+ this._emit("playBlocked", {station, error});
91
+ return false;
92
+ }
93
+ }
94
+
95
+ async stop() {
96
+ try { this.audio.pause(); } catch {}
97
+ this.audio.removeAttribute("src");
98
+ try { this.audio.load(); } catch {}
99
+ const old = this.currentStation;
100
+ this.currentStation = null;
101
+ this._emit("stopped", {station: old});
102
+ }
103
+
104
+ pause() {
105
+ this.audio.pause();
106
+ this._emit("paused", {station: this.currentStation});
107
+ }
108
+
109
+ resume() {
110
+ return this.audio.play();
111
+ }
112
+
113
+ _setMediaSession(station) {
114
+ if (!("mediaSession" in navigator)) return;
115
+
116
+ navigator.mediaSession.metadata = new MediaMetadata({
117
+ title: station.name,
118
+ artist: "ساعة المسلم",
119
+ album: "الإذاعات الإسلامية"
120
+ });
121
+
122
+ for (const [name, handler] of [
123
+ ["play", () => this.resume()],
124
+ ["pause", () => this.pause()],
125
+ ["stop", () => this.stop()]
126
+ ]) {
127
+ try { navigator.mediaSession.setActionHandler(name, handler); } catch {}
128
+ }
129
+ }
130
+ }
131
+
132
+ /*
133
+ القرآن والإذاعة لا يعملان معًا صوتيًا.
134
+ عند تشغيل الإذاعة يجب أن يوقف المشغل القرآني، والعكس صحيح.
135
+ لاحقًا يفضّل توحيدهما خلف SharedAudioManager واحد.
136
+ */
islamic_radio_registry.json ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "version": 1,
3
+ "title": "الإذاعات الإسلامية",
4
+ "playback": {
5
+ "oneActiveSourceOnly": true,
6
+ "backgroundRequested": true,
7
+ "mediaSession": true,
8
+ "externalFallback": true
9
+ },
10
+ "stations": [
11
+ {
12
+ "id": "quran_jordan",
13
+ "name": "إذاعة القرآن الكريم - الأردن",
14
+ "category": "quran",
15
+ "country": "JO",
16
+ "officialUrl": "https://www.awqaf.gov.jo/AR/Pages/%D8%A7%D9%84%D8%A8%D8%AB_%D8%A7%D9%84%D9%85%D8%A8%D8%A7%D8%B4%D8%B1",
17
+ "streamUrl": ""
18
+ },
19
+ {
20
+ "id": "quran_egypt",
21
+ "name": "إذاعة القرآن الكريم - القاهرة",
22
+ "category": "quran",
23
+ "country": "EG",
24
+ "officialUrl": "https://misrquran.gov.eg/",
25
+ "streamUrl": ""
26
+ },
27
+ {
28
+ "id": "quran_makkah",
29
+ "name": "إذاعة القرآن الكريم - مكة المكرمة",
30
+ "category": "quran",
31
+ "country": "SA",
32
+ "officialUrl": "https://quran.com/ar/radio",
33
+ "streamUrl": "https://edge.mixlr.com/channel/rwumx"
34
+ },
35
+ {
36
+ "id": "quran_mix",
37
+ "name": "إذاعة القرآن - تلاوات متنوعة",
38
+ "category": "quran",
39
+ "country": "INT",
40
+ "officialUrl": "https://quran.com/ar/radio",
41
+ "streamUrl": "https://qurango.net/radio/mix"
42
+ },
43
+ {
44
+ "id": "quran_tarateel",
45
+ "name": "إذاعة القرآن - ترتيل",
46
+ "category": "quran",
47
+ "country": "INT",
48
+ "officialUrl": "https://quran.com/ar/radio",
49
+ "streamUrl": "https://qurango.net/radio/tarateel"
50
+ },
51
+ {
52
+ "id": "seerah_mukhtasar",
53
+ "name": "مختصر السيرة",
54
+ "category": "seerah_history",
55
+ "country": "INT",
56
+ "officialUrl": "https://quran.com/ar/radio",
57
+ "streamUrl": "https://qurango.net/radio/almukhtasar_fi_alsiyra"
58
+ },
59
+ {
60
+ "id": "yaqeen_radio",
61
+ "name": "إذاعة يقين",
62
+ "category": "faith_hadith_history",
63
+ "country": "JO",
64
+ "officialUrl": "https://radioyaqeen.com/en",
65
+ "streamUrl": ""
66
+ }
67
+ ]
68
+ }
radio_architecture_notes ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ساعة المسلم — إضافة قسم الإذاعات الإسلامية
2
+
3
+ - قسم مستقل: 📻 الإذاعات الإسلامية.
4
+ - ⭐ الإذاعات المثبتة تظهر أولًا.
5
+ - التثبيت محلي ولا يحتاج حسابًا.
6
+ - التصنيفات: القرآن، السيرة والتاريخ، الحديث/المحتوى الإيماني، وغيرها.
7
+ - مشغل واحد فقط؛ تشغيل الإذاعة يوقف القرآن والعكس.
8
+ - HTML Audio + Media Session يدعمان الخلفية عندما تسمح البيئة بذلك.
9
+ - التشغيل بعد إطفاء الشاشة ليس مضمونًا على كل WebView/متصفح بالـJavaScript وحده.
10
+ - الضمان الكامل على Android يحتاج لاحقًا إلى Foreground Audio Service في التطبيق المرافق.
11
+ - كل محطة لها officialUrl احتياطي، لأن روابط البث المباشر قد تتغير.
12
+ - لا توضع قائمة الإذاعات داخل index.html؛ البيانات في Registry والمنطق في Manager.