- Home /
HTTP Live Streaming from Kii Cloud Storage?
Hi,
I'm developing an app that would use video streaming. Application would be streaming videos form Kii cloud storage. How should that be done with U3DXT?
I've tried uploading video segments as KiiObject bodies and publishing them. Next, I put their URL's in m3u8 file. After that, I uploaded m3u8 file also as KiiObject body and published it. Then, I took its URL and copied it into your Video Streaming example script (from the sneak a peak u3dxt). It couldn't play the video.
Please note that it did work when I tried uploading video segments and m3u8 to apache server on my laptop.
When I tried pasting the link to the m3u8 (the one on the Kii cloud) into Safari on my Mac, it just downloaded m3u8 file, with random name given by KiiCloud and without extension, instead of playing the video. However, when I tried adding m3u8 extension to the downloaded file and when I opened it with Safari, it streamed video perfectly, so I suppose that this issue has something to do with file extensions.
Please help me resolve this issue.
This is my code (your script from the example with altered URL for 480p stream):
using UnityEngine;
using System.Collections;
using System.IO;
using U3DXT.Core;
using U3DXT.iOS.MediaPlayer;
using U3DXT.iOS.Native.MediaPlayer;
using U3DXT.iOS.Native.Foundation;
using U3DXT.Utils;
public class StreamingMoviePlayer : MonoBehaviour {
// Use this for initialization
void Start () {
if (CoreXT.IsDevice) {
MediaExporter.ExportCompleted += OnExportCompleted;
MediaExporter.ExportFailed += OnExportFailed;
}
}
void OnDestroy() {
if (CoreXT.IsDevice) {
MediaExporter.ExportCompleted -= OnExportCompleted;
MediaExporter.ExportFailed -= OnExportFailed;
}
}
void OnExportCompleted(object sender, MediaExportedEventArgs e) {
FileInfo fileInfo = new FileInfo(e.outputURL);
Log("Exported to: " + e.outputURL);
Log("File size: " + fileInfo.Length);
}
void OnExportFailed(object sender, U3DXTErrorEventArgs e) {
Log("Export error: (" + e.domain + ": " + e.code + ") " + e.description);
}
void OnGUI()
{
KitchenSink.OnGUIBack();
if (CoreXT.IsDevice) {
GUILayout.BeginArea(new Rect(50, 50, Screen.width - 100, Screen.height/2 - 50));
GUILayout.BeginVertical();
if (GUILayout.Button("Stream 480p", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true))) {
MediaPlayerXT.PlayStreamingFullscreenMovie("https://api.kii.com/api/x/nk035ox7lcbdyj61shxhh7ok6");
}
if (GUILayout.Button("Stream 720p", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true))) {
MediaPlayerXT.PlayStreamingFullscreenMovie("http://trailers.apple.com/movies/focus_features/9/9-clip_720p.mov");
}
if (GUILayout.Button("Stream 1080p", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true))) {
MediaPlayerXT.PlayStreamingFullscreenMovie("http://trailers.apple.com/movies/focus_features/9/9-clip_1080p.mov");
}
if (GUILayout.Button("Export First Song in Music Library to Storage", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true))) {
ExportFirstSong();
}
GUILayout.EndVertical();
GUILayout.EndArea();
}
OnGUILog();
}
void ExportFirstSong() {
MPMediaQuery query = MPMediaQuery.SongsQuery();
if (query.items.Length == 0) {
Log("No songs in Music Library.");
return;
}
// get first song
MPMediaItem mediaItem = query.items[0] as MPMediaItem;
Log("Exporting song: " + mediaItem.Value(MPMediaItem.PropertyTitle));
// use null for outputFolder and outputFile to name it [artist] - [title]
if (!MediaExporter.ExportAudio(mediaItem, null, null, true))
Log("Export error or song has DRM.");
}
#region Debug logging
string _log = "Debug log:";
Vector2 _scrollPosition = Vector2.zero;
void OnGUILog() {
GUILayout.BeginArea(new Rect(50, Screen.height / 2, Screen.width - 100, Screen.height / 2 - 50));
_scrollPosition = GUILayout.BeginScrollView(_scrollPosition);
GUI.skin.box.wordWrap = true;
GUI.skin.box.alignment = TextAnchor.UpperLeft;
GUILayout.Box(_log, GUILayout.ExpandHeight(true));
GUILayout.EndScrollView();
GUILayout.EndArea();
}
void Log(string str) {
_log += "\n" + str;
_scrollPosition.y = Mathf.Infinity;
}
#endregion
}
Answer by u3dxt · Jun 16, 2014 at 09:46 PM
Hi Marko, you are correct. iOS as well as Safari have problems playing the file if there is no extension. Others are reporting the same issue doing it natively.
However, it may be possible downloading the file first and save it with an extension and play it locally. We have tried this without success though. We don't know much about streaming and maybe you can try and see if you can get it to work. One other thing to consider is inside the file, there are links to kii without file extensions. This could also be an issue.
string path = Application.temporaryCachePath + "/file.m3u8";
Debug.Log("path: " + path);
NSData data = new NSData(new NSURL("https://api.kii.com/api/x/nk035ox7lcbdyj61shxhh7ok6"));
data.WriteToFile(path, true);
MediaPlayerXT.PlayStreamingFullscreenMovie(path);
Your answer
Follow this Question
Related Questions
Pixel Stream - Camera streaming 1 Answer
Videos don't play in Apple Appstore build 0 Answers
Unity simple client server video streaming using RPC calls to send webcamTexture 2 Answers
Record a video in unity on mobile (Android, IOS) 1 Answer
U3DXT in-app purchase Init failed and everything is setup! 2 Answers