private int server_BrowseDirectChildren(Action action, String object_id, String filter, Int32 starting_index, Int32 requested_count, String sort_criteria, HttpRequestContext context) { Console.WriteLine("BrowseDirectChildren: " + object_id); if (object_id != "0") { return(-1); } var item = new MediaItem(); item.Title = "Item"; item.ObjectID = "1"; item.ParentID = "0"; item.Class = new ObjectClass("object.item.audioItem.musicTrack", ""); var resource = new MediaResource(); resource.ProtoInfo = ProtocolInfo.GetProtocolInfoFromMimeType("audio/mp3", true, context); // get list of ips and make sure the ip the request came from is used for the first resource returned // this ensures that clients which look only at the first resource will be able to reach the item List <String> ips = UPnP.GetIpAddresses(true); String localIP = context.LocalAddress.ip; if (localIP != "0.0.0.0") { ips.Remove(localIP); ips.Insert(0, localIP); } // iterate through all ips and create a resource for each foreach (String ip in ips) { resource.URI = new Uri("http://" + ip + ":" + context.LocalAddress.port + "/test/test.mp3").ToString(); item.AddResource(resource); } var didl = Didl.header + item.ToDidl(filter) + Didl.footer; action.SetArgumentValue("Result", didl); action.SetArgumentValue("NumberReturned", "1"); action.SetArgumentValue("TotalMatches", "1"); // update ID may be wrong here, it should be the one of the container? // TODO: We need to keep track of the overall updateID of the CDS action.SetArgumentValue("UpdateId", "1"); return(0); }
private int server_BrowseMetadata(Action action, String object_id, String filter, Int32 starting_index, Int32 requested_count, String sort_criteria, HttpRequestContext context) { Console.WriteLine("BrowseMetadata: " + object_id); if (object_id == "0") { var root = new MediaContainer(); root.Title = "Root"; root.ObjectID = "0"; root.ParentID = "-1"; root.Class = new ObjectClass("object.container.storageFolder", ""); var didl = Didl.header + root.ToDidl(filter) + Didl.footer; action.SetArgumentValue("Result", didl); action.SetArgumentValue("NumberReturned", "1"); action.SetArgumentValue("TotalMatches", "1"); // update ID may be wrong here, it should be the one of the container? // TODO: We need to keep track of the overall updateID of the CDS action.SetArgumentValue("UpdateId", "1"); return 0; } else if (object_id == "1") { var item = new MediaItem(); item.Title = "Item"; item.ObjectID = "1"; item.ParentID = "0"; item.Class = new ObjectClass("object.item.audioItem.musicTrack", ""); var resource = new MediaResource(); resource.ProtoInfo = ProtocolInfo.GetProtocolInfoFromMimeType("audio/mp3", true, context); // get list of ips and make sure the ip the request came from is used for the first resource returned // this ensures that clients which look only at the first resource will be able to reach the item List<String> ips = UPnP.GetIpAddresses(true); String localIP = context.LocalAddress.ip; if (localIP != "0.0.0.0") { ips.Remove(localIP); ips.Insert(0, localIP); } // iterate through all ips and create a resource for each foreach (String ip in ips) { resource.URI = new Uri("http://" + ip + ":" + context.LocalAddress.port + "/test/test.mp3").ToString(); item.AddResource(resource); } var didl = Didl.header + item.ToDidl(filter) + Didl.footer; action.SetArgumentValue("Result", didl); action.SetArgumentValue("NumberReturned", "1"); action.SetArgumentValue("TotalMatches", "1"); // update ID may be wrong here, it should be the one of the container? // TODO: We need to keep track of the overall updateID of the CDS action.SetArgumentValue("UpdateId", "1"); return 0; } return -1; }