Search code examples
iishttp-redirecturl-rewritingmp3jplayer

IIS 7.5 URL Redirect direct link to media page


I didn't think my implementation through and now I am stuck. I am using IIS 7.5, URL Rewrite 2.0 and Jplayer.

My current implementation is that I have users upload audio files to my server. To listen to these audio files, users are given a direct link to either play in the browser or through Android/iOS in app media players.

Now I have created a landing page that I want to redirect those users direct linking to the audio file to. The landing page is using Jplayer.

The problem is that I have to use the direct link to the audio file to get jplayer to play it. Since I am redirecting the direct link, it is failing to load the media url.

This also becomes a problem since my Android and iOS apps direct link to the .mp3 in order to play the file in their AV players. Is there anyway around this? Is there a better implementation? Not sure what to do at this point.

Jplayer:

        $("#jquery_jplayer_1").jPlayer({
    ready: function (event) {
        $(this).jPlayer("setMedia", {
            mp3: "http://192.168.0.28/flows/t/test/test1334187052069.mp3"
        }).jPlayer("play"); // auto play;
    },
    swfPath: "js",
    supplied: "mp3",
    errorAlerts: true,
    warningAlerts: true,
    wmode: "window"
});

IIS 7.5 Redirect Rule:

<rewrite>
    <rules>
        <rule name="FlowURLs">
            <match url="^flows/[_0-9a-zA-Z-]+/[_0-9a-zA-Z-]+/([._0-9a-zA-Z-]+)" />
            <action type="Redirect" redirectType="Found" url="music.html?flow={R:1}" />
        </rule>
    </rules>
</rewrite>

Solution

  • A possible solution might be to check the HTTP accept header and see if it's a browser expecting to load a page. If so then you redirect to your player landing page. Otherwise you leave the request as is and let it load the audio file directly.

    You can check the accept header with a conditional:

    <rewrite>
        <rules>
            <rule name="FlowURLs">
                <match url="^flows/[_0-9a-zA-Z-]+/[_0-9a-zA-Z-]+/([._0-9a-zA-Z-]+)" />
                <conditions>
                    <add input="{HTTP_ACCEPT}" pattern="text/html" />
                </conditions>
                <action type="Redirect" redirectType="Found" url="music.html?flow={R:1}" />
            </rule>
        </rules>
    </rewrite>