This project has moved. For the latest updates, please go here.

Error: Unsupported content type: M3U8 (application/vnd.apple.mpegurl)

Aug 7, 2016 at 1:29 PM
Edited Aug 7, 2016 at 1:30 PM
I have url m3u8: http://27.67.50.72:18080/2_2.m3u8?AdaptiveType=HLS
When i play it by windows phone 8 (silverlight), it raise error "Error: Unsupported content type: M3U8 (application/vnd.apple.mpegurl)"
But I know for sure that the link is correct. And with other m3u8 file, i can play. Only this link can't play (http://27.67.50.72:18080/2_2.m3u8?AdaptiveType=HLS ).
Please help me play it by windows phone 8 code.
Thank you very much.
Sorry about my english.
Coordinator
Aug 9, 2016 at 11:55 AM
I'm also getting that error when trying to play the stream.

At a guess, the stream type detection code is assuming the stream segments are actually M3U8 files based on the file extension in the segment URLs. Since M3U8 files are playlists, not media segments, it doesn't know what to do with them. I should get a chance to take a closer look tomorrow.
Aug 10, 2016 at 5:58 AM
Coordinator
Aug 11, 2016 at 5:23 AM
The problem is that when it reads the playlist, it is using the file extension in the segment URLs to determine the media type. In this example, "http://27.67.50.72:18080/2_2.m3u8?Range=5121086-5121087&SessionID=", becomes ".m3u8", which it then uses to decide that the segments are M3U8 playlist files instead of what they actually are: MPEG-2 transport streams (ContentType.TransportStream). Since it can't play M3U8 files as media segments, it gives up. There are some unpushed changes that use the ContentKind (e.g., Video, Playlist, etc.) to help determine the ContentType (e.g., TransportStream, MP3, etc) that should be sufficient to fix this.

You can try hard-coding the StreamContentType to ContentTypes.TransportStream in HlsView.WP8's TrackManager.cs to see if that is sufficient.
using SM.Media.Content;
   ...
            new MediaTrack
            {
                Title = "Test",
                Url = new Uri("http://27.67.50.72:18080/2_2.m3u8?AdaptiveType=HLS"),
                ContentType = ContentTypes.M3U8,
                StreamContentType = ContentTypes.TransportStream
            },
It works here both with and without the MediaTrack changes, but that is with both the aforementioned ContentKind changes and with some other ContentType-related changes, neither of which have been pushed to the public repository.

I'll see about getting some of these changes pushed to the public repository.
Marked as answer by ndtai2510 on 8/11/2016 at 2:05 AM
Aug 11, 2016 at 3:14 PM
Hi Henric,
I downloaded your project, but when i build, it raise error: "Could not find SDK "Microsoft.PlayerFramework.WP8.Core, Version=2.0.0.0". SM.Media.MediaPlayer.WP8"
(and more other dll missing). Could you guild for me how to get this .dll file? or how to build your projectImage
Coordinator
Aug 11, 2016 at 8:59 PM
I think you need Player Framework v2. Even without fixing those errors, you should still be able to build the HlsView.WP8 app (IIRC, only the SamplePlayer* apps, and some of its libraries need it.)
Coordinator
Aug 12, 2016 at 8:01 AM
I think c5b299b3db37 changes should be enough to get that stream running without having to specify the stream type. On the other hand, specifying the StreamContentType will save an HTTP HEAD (or possibly both a HEAD and a GET) whenever that stream starts playing.
Aug 12, 2016 at 2:17 PM
Thank you henric,
But when i download your source code at: https://phonesm.codeplex.com/SourceControl/latest#Source/Libraries/SM.Media/Playlists/MediaTrack.cs
I can not build it. it raise errors:
Error 1 Metadata file 'C:\Users\NguyenDuc\Downloads\phonesmhenric\Source\Libraries\SM.Media\bin\Debug\SM.Media.dll' could not be found C:\Users\NguyenDuc\Downloads\phonesmhenric\Source\Libraries\SM.Media.MediaPlayer.WP8\CSC SM.Media.MediaPlayer.WP8
Error 2 Metadata file 'C:\Users\NguyenDuc\Downloads\phonesmhenric\Source\Libraries\SM.Media.Platform.WP8\bin\Debug\SM.Media.Platform.WP8.dll' could not be found C:\Users\NguyenDuc\Downloads\phonesmhenric\Source\Libraries\SM.Media.MediaPlayer.WP8\CSC SM.Media.MediaPlayer.WP8
Error 3 Metadata file 'C:\Users\NguyenDuc\Downloads\phonesmhenric\Source\Libraries\SM.Media\bin\Debug\SM.Media.dll' could not be found C:\Users\NguyenDuc\Downloads\phonesmhenric\Source\Libraries\SM.Media.BackgroundAudioStreamingAgent.WP8\CSC SM.Media.BackgroundAudioStreamingAgent.WP8
Error 4 Metadata file 'C:\Users\NguyenDuc\Downloads\phonesmhenric\Source\Libraries\SM.Media.Platform.WP8\bin\Debug\SM.Media.Platform.WP8.dll' could not be found C:\Users\NguyenDuc\Downloads\phonesmhenric\Source\Libraries\SM.Media.BackgroundAudioStreamingAgent.WP8\CSC SM.Media.BackgroundAudioStreamingAgent.WP8

(...............more....)

And when i download phonesm-1.5.3-alpha.zip, build sucessfully! But MediaTrack there is no StreamContentType (Image)
Coordinator
Aug 13, 2016 at 1:25 AM
Yes, the StreamContentType was added after the 1.5.3 build.

Which solution file are you using to build? The "Samples.*.sln" files will have that problems since they are only used for the binary distribution. You should be able to get it to work anyway, but you would need to add the SM.Media, SM.Media.Builder, and SM.Media.Platform.WP8 projects to your solution (at least). It is simpler to use HlsPlayer.VS2015.sln and then right-click on the projects for platforms your are not interested in and select "Unload Project".

One can also build from the command line. The binary builds are created with Scripts\buildAll.bat.

As long as Visual Studio 2015 and Player Framework v2 are installed, this should work:
  1. Unzip or git clone the source
  2. Open a standard CMD window
  3. CD to where you put the source
  4. Run "Scripts\buildAll.bat"
When that is done, there should be a "Distribution" directory with the same files that are in the binary distribution ZIP file that I provide (well, I don't include the NuGet packages or sample app build files in the distribution zip).
Aug 13, 2016 at 2:56 AM
When i run "Scripts\buildAll.bat", these command only create directory, there are no any file. maybe have some error with vsvars32.bat
Image
Coordinator
Aug 13, 2016 at 4:49 AM
It is using the VS140COMNTOOLS environment variable to locate Visual Studio 2015's vsvars32.bat file. Is that variable not set on your system? The VS2015 installer should have set it.

Mine looks like this:
VS140COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\
Hmmm... Looks like other's have had problems with that variable too:
http://stackoverflow.com/questions/31680687/vs2015-msbuild-vsvars32-bat-cannot-determine-the-location-of-the-vs-instal
Aug 13, 2016 at 3:38 PM
Edited Aug 16, 2016 at 10:25 AM
Oh...No. My visual studio is version 13 (Visual studio 2013), Unfortunately, my loptop can't setup visual 2015.
Coordinator
Aug 17, 2016 at 1:27 AM
ndtai2510 wrote:
Oh...No. My visual studio is version 13 (Visual studio 2013), Unfortunately, my loptop can't setup visual 2015.
I'm not sure of the state of C# 6 support in VS2013 (is there a NuGet package that would work for the phone?). However, you can still get either the 1.5.3 binary build or get source from before 3f03ac2a2d4f. The easiest way to do is probably to provide an implementation of IContentTypeDetector that returns the right ContentType instance for this stream.

Something like this should work in HlsView.WP8's MainPage.xaml.cs:
using SM.Media.Content;
   ...
        class FixedContentTypeDetector : ContentTypeDetector
        {
            public FixedContentTypeDetector(IEnumerable<ContentType> contentTypes) : base(contentTypes)
            { }

            public override ICollection<ContentType> GetContentType(Uri url, ContentKind kind, string mimeType = null, string fileName = null)
            {
                if (url.Host == "devimages.apple.com")  // Or some other test, depending on what streams you are playing
                {
                    return new[] {  kind == ContentKind.AnyMedia ? SM.Media.Content.ContentTypes.TransportStream : SM.Media.Content.ContentTypes.M3U8 };
                }

                return base.GetContentType(url, kind, mimeType, fileName);
            }
        }

        void InitializeMediaStream()
        {
            if (null != _mediaStreamFacade)
                return;

            // Enable UseHttpConnection to use sockets directly instead of going through
            // the system's default HTTP client.  HttpConnection is not as picky about
            // headers and it will not pollute the system's HTTP cache, but it will always
            // open a new connection for each request.
            //MediaStreamFacadeSettings.Parameters.UseHttpConnection = true;

            _mediaStreamFacade = MediaStreamFacadeSettings.Parameters.Create();

            // Use a custom IContentTypeDetector
            _mediaStreamFacade.Builder.RegisterSingleton<IContentTypeDetector, FixedContentTypeDetector>();

            _mediaStreamFacade.StateChange += TsMediaManagerOnStateChange;
        }
Coordinator
Aug 17, 2016 at 1:35 AM
Edited Aug 17, 2016 at 2:10 AM
If the version of IContentTypeDetector you are building with does not have the "ContentKind" parameter, then you will need to base the return value entirely on the URL (the mimeType and filename will be null).

And yes, this would all be much simpler if phonesm opened the connection and grabbed the HTTP headers before creating the media handler...