Access to source code for video player?

I am building a player for very large (Dolby surround) wav files. I need to play them in the background. I have made a Native ios version that works well playing them in the background with the AVPlayer and AVAudioPlayer from iOS, but those functions first download the entire file before playing. I have found 2 packages (SwiftAudioPlayer, AudioStreaming) that do what I want, but they choke on streaming the large files (stutter and freeze the app). The video player in Solar2d works great streaming these large files, I was just wondering if it would work to just put the session

session setCategory:AVAudioSessionCategoryAmbient
and
session setCategory:AVAudioSessionCategoryPlayback

into the Solar2d players to make them work in background. I know there are UI issues, but I think I have taken care of those. I would be happy to experiment if I had the relevant code.

The video player for iPhone is here. I couldn’t tell you if it depends much on other parts in the code, but what came up otherwise with the “videoplayer” query seemed to mostly be access calls to the player.

Thank you. I can see where to try to modify it. But if I bring it down and change it, how do I get my version to be used instead of the standard one?

Ah, I wasn’t sure if your “Native ios version” meant you had just decided to do this separately and wanted to copy some behavior.


If you go up one directory to the iPhone platform page, there are some instructions about running it with the assets2 folder. If you think you’ve got something useful enough to contribute, you could fork the corona repository and make a pull
request.

See also Contributing (Note the “recursive”: if you just download the zip, you’ll miss the submodules.)

1 Like

Thank you, I doubt my code would be very useful. It is iOS-only, and I did all the actual work in Swift. It is very simple and not completely debugged. I posted the finished module below. As you see, it is very simple, but does what I need. The critical pieces for background are in the session.setCategory

//
//  SwSound.swift
//  SoundScape
//
//  Created by David Marques on 5/2/24.
//

import Foundation
import AVFoundation

var player : AVPlayer!
var inactive = true

public class SwSound : NSObject {
    
    var session = AVAudioSession.sharedInstance()
    var ctstime = CMTime()
    
//    override init() {
    
    func activateSession() {
        do {
            try session.setCategory(
                .playback,  //allows app to keep playing while in the background
                mode: .default,
                options: [.mixWithOthers] // allows other app sounds to mix
            )
        } catch _ {}
        
        do {
            try session.setActive(true, options: .notifyOthersOnDeactivation)
        } catch _ {}
        
        do {
            try session.overrideOutputAudioPort(.speaker)
        } catch _ {}
//        player = AVPlayer()
    }

    @objc func pause() {
        print("in Swift pause");
        if (player.rate != 0) {
            print("pauseing");
            player.pause()
        }
    }
    
    @objc func setup() {
        print("swsound setup")
        activateSession()
        createPlayer()
    }
    
    @objc func seek(_ stime: Double) {
        ctstime = CMTimeMakeWithSeconds(stime, preferredTimescale: 1)
//        player.seek(to: ctstime)
    }

    @objc func currentTime() -> Double {
//        print("in Swift currentTime");
        var ct = 0.1
        if (player.rate != 0) {
            ct = Double(Float(CMTimeGetSeconds(player.currentTime())))
            print("currentTime: " + String(format: "%f", ct))
        }
        return ct
    }
    
    @objc func createPlayer(){
        player = AVPlayer()
    }

    @objc func playRemote(_ fileName: NSString) {
        print("in Swift " + (fileName as String));
        let url = URL(string: fileName as String)!
        
        //------------
        // Standard AVPlayer
        let playerItem: AVPlayerItem = AVPlayerItem(url: url)
        player.replaceCurrentItem(with: playerItem)
        player.seek(to: ctstime)
        player.play()
        //---------

    }

    
}

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.