MCPcopy Create free account
hub / github.com/OpenShot/libopenshot / Play

Method Play

src/Frame.cpp:930–998  ·  view source on GitHub ↗

Play audio samples for this frame

Source from the content-addressed store, hash-verified

928
929// Play audio samples for this frame
930void Frame::Play()
931{
932 // Check if samples are present
933 if (!GetAudioSamplesCount())
934 return;
935
936 juce::AudioDeviceManager deviceManager;
937 juce::String error = deviceManager.initialise (
938 0, /* number of input channels */
939 2, /* number of output channels */
940 0, /* no XML settings.. */
941 true /* select default device on failure */);
942
943 // Output error (if any)
944 if (error.isNotEmpty()) {
945 cout << "Error on initialise(): " << error << endl;
946 }
947
948 juce::AudioSourcePlayer audioSourcePlayer;
949 deviceManager.addAudioCallback (&audioSourcePlayer);
950
951 std::unique_ptr<AudioBufferSource> my_source;
952 my_source.reset (new AudioBufferSource (audio.get()));
953
954 // Create TimeSliceThread for audio buffering
955 juce::TimeSliceThread my_thread("Audio buffer thread");
956
957 // Start thread
958 my_thread.startThread();
959
960 juce::AudioTransportSource transport1;
961 transport1.setSource (my_source.get(),
962 5000, // tells it to buffer this many samples ahead
963 &my_thread,
964 (double) sample_rate,
965 audio->getNumChannels()); // sample rate of source
966 transport1.setPosition (0);
967 transport1.setGain(1.0);
968
969
970 // Create MIXER
971 juce::MixerAudioSource mixer;
972 mixer.addInputSource(&transport1, false);
973 audioSourcePlayer.setSource (&mixer);
974
975 // Start transports
976 transport1.start();
977
978 while (transport1.isPlaying())
979 {
980 cout << "playing" << endl;
981 std::this_thread::sleep_for(std::chrono::seconds(1));
982 }
983
984 cout << "DONE!!!" << endl;
985
986 transport1.stop();
987 transport1.setSource (0);

Callers

nothing calls this directly

Calls 2

resetMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected