Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

508
Visualizações
iOS: How to intercept and manipulate bytes in AVPlayer

Is there a way to intercept byte data and perform a XOR operation to each byte prior to playing audio in AVPlayer?

I'm building an audio streaming app and use a little script written in C to add a simple layer of encryption to the MP3 files. In Android it gets decoded in real time like this:

@Override
public int read(byte[] buffer, int offset, int readLength) throws FileDataSourceException {
        // ...
        if (readLength == 1 && offset >= 1 && offset <= 123) {
            buffer[offset] = (byte)(buffer[offset] ^ 11);
        }

        return bytesRead;
    }
}

As you can see above reversing the XOR encryption is fairly easy in Android as I use ExoPlayer and override the read() method in its datasource classes. Is there any chance to perform the same thing using AVPlayer with Swift?

Here's a flowchart of the whole idea:

AVPlayer encryption flowchart

Thank you.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You'll want to use MTAudioProcessingTap for this, which is a property of AVPlayer's AVAudioMix. In your tap process callback, use MTAudioProcessingTapGetSourceAudio to grab your buffers. Once you have your buffer reference you can xor the data.

There's some boilerplate needed to get the AVAudioMix and MTAudioProcessingTap setup properly. The sample code that Apple has is pretty old, but still should work. https://developer.apple.com/library/archive/samplecode/AudioTapProcessor/Introduction/Intro.html#//apple_ref/doc/uid/DTS40012324

Also note that it will be easier to do this in Objective C, for several reasons. The interop with your C file will be easier, and it is much more straightforward reading/writing to the buffer in Objc. It will also run faster than in swift. If you are interested to seeing what this would look like in swift, there is a sample project here: https://github.com/gchilds/MTAudioProcessingTap-in-Swift

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda