3

I don't even know if the title for this question is appropriate, since I'm really lost and need some advice, a starting point to what I need to accomplish.

My iPhone app plays audio streamed from the Internet, with my custom made player. Some links are live streams from Akamai and others are audio files stored on a website. I'm OK with the live streams, but my problem is with the audio files.

As I have many stored audio files that the user can choose from, in different languages, and I don't want to hardcode all of them on my application.Then I need a clever way for the user to browse on the app (pushing the information from the Internet) until he reaches the desired file to play.

The website is organized like this:

First there is list, having all available programs. The user chooses the desired program, then another page shows up and he has to choose a day of the week to play.

My question is: how can I parse this content, with programs and days of the week to choose from? Should I look into HTML parsing? Is there a better/simpler way, like making XML files on the website?

If this helps, the all the webpages end with the .aspx extension.

Please, any advise from a more experienced programmer will greatly help me. Thank you!

neowinston
  • 7,584
  • 10
  • 52
  • 83

5 Answers5

2

I don't think parsing HTML would be the best implementation here. Go for a structured source that doesn't have viewable markup to worry about parsing out or ignoring altogether (also will mean fewer resources thrown at parsing the markup because you will only be parsing what matters).

I'd suggest consuming an XML or JSON source that can be converted to a NSDictionary or other data structure for app use. Here's a neat little class that converts an XML source to an NSDictionary: http://troybrant.net/blog/2010/09/simple-xml-to-nsdictionary-converter/

TBXML is another light-weight XML parser for Objective-C that makes implementing a custom data object up to you: http://www.tbxml.co.uk/

If you'd rather use JSON, there are a number of helpers out there. A good place to start looking would be here: http://cocoaobjects.com/?s=json

If I have understood your question correctly, whatever source you choose, you're likely to want to wind up with a dictionary object that looks something like this:

programs = (
  {
    program_name: "Foo";
    tracks = (
      { day: Monday;
        track: audio_file1.mp3;
      },
      { day: Tuesday;
        track: audio_file2.mp3;
      },
      { day: Wednesday;
        track: audio_file3.mp3;
      }
    );
  },
  {
    program_name: "Bar";
    tracks = (
      { day: Monday;
        track: audio_file4.mp3;
      },
      { day: Tuesday;
        track: audio_file5.mp3;
      },
      { day: Wednesday;
        track: audio_file6.mp3;
      }
    );
  },
  {
    program_name: "Baz";
    tracks = (
      { day: Monday;
        track: audio_file7.mp3;
      },
      { day: Tuesday;
        track: audio_file8.mp3;
      },
      { day: Wednesday;
        track: audio_file9.mp3;
      }
    );
  };
);

Once you've worked out your data source, and converted it to a native data object for working with in Obj-C, you should be able to proceed with coding up a UI that can iterate through the dictionary to provide a list of programs and, in turn, a list of days for each program with accompanying audio files to select to play.

bobwaycott
  • 526
  • 2
  • 7
  • Thanks a lot for your insight! I think this is pretty much the way to go. Would you care to take a look at real scenario? I can leave my email here, I could have yours, to send you the actual web pages. Thanks again. – neowinston Nov 12 '11 at 14:36
  • This is probably bad idea because the data is monolithic and requires to download and parse potentially huge file. Let's say i have 500 programs and 500 days of recordings, that is potentially 250000 entries – Nas Banov Nov 14 '11 at 09:51
  • @NasBanov Why wouldn't a dev stagger the loading mechanism to solve this problem? I certainly wasn't suggesting downloading massive datasets. However, there are multiple other ways these requests could be retrieved--either by some lazy loading or paged result set. Not to mention JSON can deliver good data in a small package. Once a working implementation was in place, you could tweak at will to improve performance. – bobwaycott Nov 16 '11 at 06:38
  • @Winston I was going to say sure (I stay pretty busy and don't make it back every day), but I see the bounty was awarded to another poster. Hope you get a working implementation. – bobwaycott Nov 16 '11 at 06:40
  • I thank you for all your insights and attention! I'm working on a JSON implementation. It seems to be very fast and reliable. – neowinston Nov 16 '11 at 12:45
2

I had a similar need. Consuming data from an ASP.NET site. In the end I used JSON from the .NET side and return JSON. Then, I used the json-framework from Google Code to convert the JSON returned to an NSDictionary. From there the rest is history.

If you are using .NET MVC, then returning JSON results is super simple in a controller. Since you have aspx extensions, I assume that is not the case. There are tons of JSON parsers for C# listed at the bottom of the json.org homepage.

uadrive
  • 1,249
  • 14
  • 23
  • I'm not the web site administrator. I'm assuming that I'd make a JSON file to be incorporated into the ASP.NET code, by the administrator, right? Thanks for your time! – neowinston Nov 13 '11 at 15:20
  • Providing a JSON file would definitely be one way to do it. Is there a specific format that the web site administrator is providing? If you can work with the website administrator, I'd work on sending them something that they can return a searched list with. – uadrive Nov 13 '11 at 15:25
  • Thanks a lot for your insight! I think this is pretty much the way to go. Would you care to take a look at real scenario? I can leave my email here, I could have yours, to send you the actual web pages. – neowinston Nov 13 '11 at 16:30
  • Sure, I would be happy to look at them. – uadrive Nov 13 '11 at 17:00
  • Please send me a message to neo-winston@hotmail.com and I'll rely. Thanks. – neowinston Nov 13 '11 at 17:08
  • if you think about it, there is even no need about JSON nor XML - the lists can be provided in plain text (which the web server will gladly deliver as plain/text) and parsed on \n, which is trivial. – Nas Banov Nov 14 '11 at 21:31
1

if the website content is static, I would hard code the file names and appropriate URL's to your server within the app and let the user scroll through the list of available items.

if the website content changes, then I would create an XML file on a server which your app downloads on launch (or as you deem fit) and parse within the app, then continue as per static content.

hope this starts you off in the right direction.

Nik Burns
  • 3,363
  • 2
  • 29
  • 37
  • Hi Nik, thanks for your answer! Actually I've already hardcoded the URLs for the English audio, and as the user makes his choices the proper audio file plays accordingly. But I have 8 different languages to do the same thing, then it will soon become a cumbersome task. Not to mention that I don't speak neither Chinese nor Japanese, just to mention two different Asian languages. – neowinston Nov 09 '11 at 23:52
  • Do you think that using TouchXML and a .xml file on the server it could be done? I'm already using TouchXML to parse the.asx files to play various audio files in sequence. Thanks again for your attention and your thoughts on this will very much appreciated. – neowinston Nov 09 '11 at 23:53
  • could you elaborate on the language problem? if I'm understanding correctly. you need to localise the audio files name to the user in a number of languages. if you create an xml file with language tags then the app can use the correct language name based on the device locale setting. – Nik Burns Nov 11 '11 at 15:26
  • Actually for each web page, for the 8 different idioms, I have many corresponding audio files. The only thing in common is the way the web sites have been designed. Do you need more info? – neowinston Nov 11 '11 at 16:40
  • i think you will need to post how the server info is layed out. you had mentioned that the website info is ok, just the servers? sorry, am confused. – Nik Burns Nov 11 '11 at 17:56
  • Nik, would you like me to sent you the web site links, so you would see for yourself? I can put here my email address, then you send me an email and will reply with detailed information. Thanks! – neowinston Nov 11 '11 at 18:20
  • Great! I'm sending you a message and I do appreciate your attention, and thanks for sharing your knowledge. – neowinston Nov 11 '11 at 20:39
1

If it were me, and assuming I have some clue as to what you're talking about, I would have a database that shows the relationship between the audio content and the date. Then your spinner for the content would just be updated by a query...

So, for instance, assume a table

+----------------------------------------------------------------------+
| Filename                        | Language          | Date           |
+----------------------------------------------------------------------+
| kjslfiewofksalfjslfakj          | Swahili           | 2011-11-01     |
| shfaahflajfewifhlanfww          | Guyanese          | 2011-10-08     |
| weijalfjlajfljalsfjewn          | French            | 2011-11-01     |
| fiwojancanlsjfhkwehwlk          | Swahili           | 2011-11-01     |
| fhalksflwiehlfnaksflhw          | Swahili           | 2011-11-03     |
+----------------------------------------------------------------------+

Okay, so if joe schmo reaches the page for the show dated 2011-11-01 and his language is Swahili, two rows will be returned:

+----------------------------------------------------------------------+
| Filename                        | Language          | Date           |
+----------------------------------------------------------------------+
| kjslfiewofksalfjslfakj          | Swahili           | 2011-11-01     |
| fiwojancanlsjfhkwehwlk          | Swahili           | 2011-11-01     |
+----------------------------------------------------------------------+

You could also easily add references for the date and language that indicate an Akamai record. It doesn't strike me as terribly complicated, but it may mean significant redesign for you. However, you've been purposefully vague on details, so hopefully at least this points you in a right direction.

Edit:

Alright, so after re-reading, there may be a relatively easy way to control content in its organization by using directory structures, but it takes a backseat to my proposed table.

As I understand it, there are potentially three categories at work: program, date, and language.

If I create a file structure (assuming root):

/public_html/audio/[date]/[language]/[program_name].mp4

Then, when the user selects a date and language, we might have:

/public_html/audio/2011-11-14/swahili/the_linux_show.mp4

Then, all we'd have to do is have the $_POST data from the selectors read to provide the show... Unfortunately, this will mean that we have to know the date that the show aired, then language, then show name. This would be a far worse way than a database, but could be done. Use ASP to read directory contents and you can list using loops. Seems pretty simple, but not at all elegant.

stslavik
  • 2,920
  • 2
  • 19
  • 31
  • Hi friend, and thanks for your answer. Yes, I didn't want to be more specific but I could send you an email detailing the real scenario. Would you like to have my address, or leave yours here? Your help will be much appreciared. – neowinston Nov 11 '11 at 23:55
  • Both my email and website are in my profile, and you're welcome to contact me through either. My point, however, is this: You're using a dynamic scripting language (ASP) to produce a page, so why not make the most of it. Either use a database to control content, or organize your file structure accordingly. After re-reading your OP, I'll create an edit to suggest an alternate file structure. – stslavik Nov 14 '11 at 18:40
1

Think outside the box: use UIWebView

How about instead of thinking how to parse data and then write UI code to display it we think more of the big picture: we want to present to iPhone user sequence of screens to select and play a recording, and this should be coming from a web server. Only if there was such a tool... but wait, there is! It's called web browser and in the form of UIWebView you can integrate it in your interface, with a little twist.

First, adding UIWebView is very easy, check this http://zpasternack.blogspot.com/2010/09/stupid-uialertview-tricks-part-i.html for illustration.

So let's say we added web view and user can select an audio file from there, what happens then? Turns out you can tell it what should happen, check this question UIWebView open links in Safari . You can hook your code into handling of link clicks and do whatever you please (like hide web view and show player etc).

To give an example, say first in the web view you load
http://foobar.com/somepath/listOfPrograms
which happens to be web page showing list of the programs (which thanks on some clever CSS could look just like an UITableView if you please). User clicks on a programing name, that goes to
http://foobar.com/somepath/programs/CarTalk
which page presents list of weekly shows (again iPhonesque formatted) and when clicked on a link, this now points to
http://audio.foobar.com/somesuch/45678913.mp3
at which point your code recognizes that's audio URL, apprehends control and plays it however it pleases.

How useful is that you may wonder. The answer is "very" :-). It moves the presentation structure away from the app - and to the web server. The app's entry into the UIWebView is the initial URL and the exit is click on audio file link. In a few months someone decides they want the choices not to be made fist programming name and then day of the week; or add additional layer of choice by language or country. No problemo, no need to release new version of the app, just tweak a bit the web pages on the server and the app will pick it up automagically.

It also makes testing the web server side easy - just point any browser to the initial page URL and click-through to see if you make it to a viable audio file. The web master can handle that independently of you, the app writer. You don't even have to care what they use on their side to get those pages, is it hard-coded in html, or comes from a SQL DB, XML tarpit, whatever.

Community
  • 1
  • 1
Nas Banov
  • 28,347
  • 6
  • 48
  • 67
  • Hi Nas! Thanks for your answer. I've thought about that, and even tried using an UIWebView, which would be a great solution. But the page displays tiny menus, since it's not formated for the iPhone. Besides, there are lots of other unnecessary links and would have to reprogram my custom wma over mms:// player. What do you suggest about these small menus? Would be necessary to a custom webpage for the iPhone and/or iPad? Thank you again. – neowinston Nov 14 '11 at 14:32
  • @Winston: i did not mean you should use the existing website pages (with small links, menus and whatnot). You can design your own versions to be hosted in parallel to the full-browser experience. Although if you are good with CSS - why yes, you could use the existing pages in such a way that they will re-format for iPhone and displaye only big menus and no carp. Whichever of the two works for you. I don't understand why you'd need to reprogram your custom "wma over mms://" player. – Nas Banov Nov 14 '11 at 21:34
  • I appreciate your reply, and after posting my answer to you I realized that indeed I'll not need to change my player, but only modify a little bit the way it starts playing. I'll talk to the web programmer to see what we could be working together. Thanks! – neowinston Nov 14 '11 at 22:11