Skip to content

Commit

Permalink
Better handles ad announcements
Browse files Browse the repository at this point in the history
  • Loading branch information
JudahGabriel committed Dec 5, 2024
1 parent fbbdcc7 commit c157f79
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
9 changes: 5 additions & 4 deletions Chavah.NetCore/Controllers/CdnController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ public RedirectResult GetStationId()
/// <returns></returns>
public RedirectResult GetAdAnnouncement()
{
var sukkotAd = "sukkot2024.mp3";
// var sukkotAd = "sukkot2024.mp3";
var ads = new[]
{
sukkotAd,
// sukkotAd,
"ad1x.mp3",
"ad2x.mp3",
"ad3x.mp3",
Expand All @@ -96,9 +96,10 @@ public RedirectResult GetAdAnnouncement()
};

// Sukkot 2024 ad: play it every even hour.
var fileName = DateTime.UtcNow.Hour % 2 == 0 ? sukkotAd : ads.RandomElement()!;
//var fileName = DateTime.UtcNow.Hour % 2 == 0 ? sukkotAd : ads.RandomElement()!;
var fileName = ads.RandomElement();
var directory = new Uri(cdnSettings.Value.HttpPath).Combine(cdnSettings.Value.SoundEffects);
return Redirect(directory.Combine(fileName).AbsoluteUri);
return Redirect(directory.Combine(fileName!).AbsoluteUri);
}

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion Chavah.NetCore/wwwroot/js/Controllers/HeaderController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@

// Tell the user if they have unread notifications after a bit.
this.$timeout(() => {
console.log("zanz", this.notifications && this.notifications.filter(n => n.isUnread).length > 0);
if (this.notifications && this.notifications.filter(n => n.isUnread).length > 0) {
this.highlightUnreadNotifications = true;
}
Expand Down
18 changes: 16 additions & 2 deletions Chavah.NetCore/wwwroot/js/Services/AdAnnouncerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,22 @@
}

playAdAnnouncement() {
const songUrl = "/api/cdn/getAdAnnouncement";
this.audioPlayer.playNewUri(songUrl);
const adUrl = "/api/cdn/getAdAnnouncement";

// Check if this is a redirect. If so, find the target of the redirect and play that.
// If not, play the URL.
// Reason is, on iOS we use native audio to play the URL. It can have issues playing a redirect result.
window.fetch(adUrl)
.then(res => {
const isRedirect = res.status >= 300 && res.status < 400;
if (isRedirect) {
const redirectUrl = res.headers.get("Location");
this.audioPlayer.playNewUri(redirectUrl || adUrl);
}
}, err => {
console.warn("Unable to fetch ad announcement URL due to error", err);
this.audioPlayer.playNewUri(adUrl);
});
}
}

Expand Down
Binary file modified MessiahsMusicFundDisbursement.xlsx
Binary file not shown.

0 comments on commit c157f79

Please sign in to comment.