2

I'm developing a radio app for iOS and need to be able to parse metadata from an audio stream with an encoding that supports Norwegian characters "ÆØÅ".

Using timedMetaData on an AVPlayerItem these three characters are displayed as "ÃÃÃ".

Does anyone know how to change the encoding on the value (not stringValue) of a timedMetaData item? Or perhaps how to get the raw value?

Code example:

private var url = ""
private var player: AVPlayer!
private var playerItem: AVPlayerItem!

playerItem = AVPlayerItem(URL: NSURL(string: url)!)
player = AVPlayer(playerItem: playerItem)
playerItem.addObserver(self, forKeyPath: "timedMetadata", options: NSKeyValueObservingOptions.New, context: nil)

override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {

    guard keyPath == "timedMetadata" else { return }

    for item in playerItem.timedMetadata! {

        if item.commonKey == "title" {

            let value = item.value

            print(value)
            //metadata = item.stringValue!
        } else {
            print(item.key)
        }
    }
}
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
tomen
  • 31
  • 4

1 Answers1

-1

I found the solution using C# / Xamarin. You need to encode the metadata with ISOLatin1, then to UTF8:

NSString str = new NSString(item.StringValue);
var data = str.Encode(NSStringEncoding.ISOLatin1, true);
string meta = new NSString(data, NSStringEncoding.UTF8);
Tommy Ovesen
  • 400
  • 3
  • 11
  • This is a question about using the IOS SDK and the AVPlayerItem class. It is not a programming language questing. My answer solves the problem using IOS SDK classes in C#. A person with knowledge about Swift and IOS SDK would easily understand how to use this code – Tommy Ovesen May 22 '17 at 14:06
  • Thanks! That should do it. I totally forgot this post as we decided to use StreamingKit instead of AVPlayer. – tomen May 23 '17 at 07:35