0

I have a NSData object, obtained from a URL request.Now I don't know how to read it.
However in my application I don't know if the data contains a video or not, so I would know:

  1. How to know if NSData has some video inside it?
  2. How to interpret the data, reading it byte per byte?
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
Ramy Al Zuhouri
  • 21,580
  • 26
  • 105
  • 187
  • 1
    Ask whoever sent it to you. Bits is bits. You can look at the first dozen or so bytes and guess what you might have, but you need to first narrow it down to a list of possibilities. – Hot Licks Nov 08 '12 at 00:48

2 Answers2

2

I'm not familiar with the particular API you're using so I can't say what the code should be, but any web/HTTP client library should provide you the Content-Type of the data as well as the data itself. Use the Content-Type (and only the Content-Type; doing otherwise can lead to security bugs) to determine how to interpret the content. For example, if the Content-Type (also known as MIME type) starts with video/, then the content is definitely video; the part after the slash will tell you the specific format to interpret it as.

Kevin Reid
  • 37,492
  • 13
  • 80
  • 108
  • 3
    Relying on Content-Type will not prevent security problems -- Content-Type can easily be spoofed. But you're right that it's the "proper" way to identify the type of data. – Hot Licks Nov 08 '12 at 01:49
  • The MIME type is always text/html, but there is a video embedded in the html code.The URL is from you tube.I'm not using a particular API, just cocoa framework: NSURLConnection, sending an asynchronous request. – Ramy Al Zuhouri Nov 08 '12 at 10:07
0

If you intend to play the video that the data may contain, then just do that. Whichever playback API you use should give you an error if the data isn't anything it recognizes.

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370