iosobjective-cencodingbase64string-decoding

How do I get audio/video from base64 encoded string?


In JSON file, I am receiving the base64 encoded string. It may contain image file, pdf file, doc or text file or audio/video file.

How can I show/play audio/video in iOS from base64 encoded string?

I implemented code for images, doc, pdf, text files except for audio/video file. I used below code to achieve this,

//for image

NSURL *url = [NSURL URLWithString:base64String];    
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage *ret = [UIImage imageWithData:imageData];

//for ppt, pdf, doc, and textfile

    NSData* myData = [NSData dataFromBase64String: base64EncodedString];
    [_webView loadData:myData
                 MIMEType:@"application/pdf"
         textEncodingName:@"NSUTF8StringEncoding"
                  baseURL:[NSURL URLWithString:@"https://www.google.co.in/"]];

Solution

  • //try this simple logic as per your code
    
    NSURL *URL = [NSURL URLWithString:
                                  [NSString stringWithFormat:@"data:audio/mp3;base64,%@",
                                   yourBase64EncodedString]];
    
    
     [_webView loadRequest:[NSURLRequest requestWithURL:URL]];