1fa7767c5Sopenharmony_ci/* 2fa7767c5Sopenharmony_ci * Copyright (c) 2022-2022 Huawei Device Co., Ltd. 3fa7767c5Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fa7767c5Sopenharmony_ci * you may not use this file except in compliance with the License. 5fa7767c5Sopenharmony_ci * You may obtain a copy of the License at 6fa7767c5Sopenharmony_ci * 7fa7767c5Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fa7767c5Sopenharmony_ci * 9fa7767c5Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fa7767c5Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fa7767c5Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fa7767c5Sopenharmony_ci * See the License for the specific language governing permissions and 13fa7767c5Sopenharmony_ci * limitations under the License. 14fa7767c5Sopenharmony_ci */ 15fa7767c5Sopenharmony_ci#include <chrono> 16fa7767c5Sopenharmony_ci#include <fcntl.h> 17fa7767c5Sopenharmony_ci#ifndef WIN32 18fa7767c5Sopenharmony_ci#include <sys/types.h> 19fa7767c5Sopenharmony_ci#include <unistd.h> 20fa7767c5Sopenharmony_ci#define O_BINARY 0 // which is not defined for Linux 21fa7767c5Sopenharmony_ci#endif 22fa7767c5Sopenharmony_ci#include <math.h> 23fa7767c5Sopenharmony_ci#include <thread> 24fa7767c5Sopenharmony_ci#include "helper/test_player.hpp" 25fa7767c5Sopenharmony_ci#include "testngpp/testngpp.hpp" 26fa7767c5Sopenharmony_ci#include "foundation/log.h" 27fa7767c5Sopenharmony_ci 28fa7767c5Sopenharmony_ciusing namespace OHOS::Media::Test; 29fa7767c5Sopenharmony_ci 30fa7767c5Sopenharmony_ci// @fixture(tags=audio_play_fast) 31fa7767c5Sopenharmony_ciFIXTURE(DataDrivenSinglePlayerTestFast) 32fa7767c5Sopenharmony_ci{ 33fa7767c5Sopenharmony_ci bool CheckTimeEquality(int32_t expectValue, int32_t currentValue) 34fa7767c5Sopenharmony_ci { 35fa7767c5Sopenharmony_ci MEDIA_LOG_I("expectValue : %d, currentValue : %d", expectValue, currentValue); 36fa7767c5Sopenharmony_ci return fabs(expectValue - currentValue) < 1000; // if open debug log, should use value >= 1000 37fa7767c5Sopenharmony_ci } 38fa7767c5Sopenharmony_ci 39fa7767c5Sopenharmony_ci DATA_PROVIDER(myurls, 1, 40fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/MP3/MP3_LONG_48000_32.mp3")), 41fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/MP3/MP3_48000_32_SHORT.mp3")), 42fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/AAC/AAC_48000_32_SHORT.aac")), 43fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/FLAC/vorbis_48000_32_SHORT.flac")), 44fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/M4A/MPEG-4_48000_32_SHORT.m4a")), 45fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/WAV/vorbis_48000_32_SHORT.wav")), 46fa7767c5Sopenharmony_ci DATA_GROUP(std::string("http://localhost/resource-src/media/MP3/MP3_48000_32_SHORT.mp3"))); 47fa7767c5Sopenharmony_ci 48fa7767c5Sopenharmony_ci DATA_PROVIDER(shortMusicUrls, 1, 49fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/M4A/MPEG-4_48000_32_SHORT.m4a")), 50fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/WAV/vorbis_48000_32_SHORT.wav")), 51fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/AAC/AAC_48000_32_SHORT.aac")), 52fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/FLAC/vorbis_48000_32_SHORT.flac")), 53fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/MP3/MP3_LONG_48000_32.mp3")), 54fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/WAV/vorbis_48000_32_SHORT.wav")), 55fa7767c5Sopenharmony_ci DATA_GROUP(std::string("http://localhost/resource-src/media/MP3/MP3_48000_32_SHORT.mp3"))); 56fa7767c5Sopenharmony_ci 57fa7767c5Sopenharmony_ci DATA_PROVIDER(longMusicUrls, 1, 58fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/MP3/MP3_LONG_48000_32.mp3")), 59fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/M4A/MPEG-4_48000_32_LONG.m4a")), 60fa7767c5Sopenharmony_ci DATA_GROUP(std::string("http://img.51miz.com/preview/sound/00/26/73/51miz-S267356-423D33372.mp3")), 61fa7767c5Sopenharmony_ci DATA_GROUP(std::string("http://localhost/resource-src/media/MP3/MP3_LONG_48000_32.mp3"))); 62fa7767c5Sopenharmony_ci 63fa7767c5Sopenharmony_ci DATA_PROVIDER(durationTestMusicUrls, 2, 64fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/MP3/MP3_LONG_48000_32.mp3"), 30000), 65fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/AAC/AAC_LONG_48000_32.aac"), 30000), 66fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/FLAC/FLAC_48000_32_LONG.flac"), 30000), 67fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/WAV/vorbis_48000_32_SHORT.wav"), 5000), 68fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/M4A/MPEG-4_48000_32_LONG.m4a"), 30000)); 69fa7767c5Sopenharmony_ci 70fa7767c5Sopenharmony_ci DATA_PROVIDER(FileFdSourceTestShortMusicUrls, 2, 71fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/M4A/MPEG-4_48000_32_SHORT.m4a"), 36715), 72fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/WAV/vorbis_48000_32_SHORT.wav"), 524472), 73fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/AAC/AAC_48000_32_SHORT.aac"), 49233), 74fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/FLAC/vorbis_48000_32_SHORT.flac"), 217292), 75fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/MP3/MP3_48000_32_SHORT.mp3"), 24697), 76fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/OGG/OGG_48000_SHORT.ogg"), 30912), 77fa7767c5Sopenharmony_ci DATA_GROUP(std::string(RESOURCE_DIR "/APE/MPEG-4_48000_32_SHORT.ape"), 161018)); 78fa7767c5Sopenharmony_ci 79fa7767c5Sopenharmony_ci DATA_PROVIDER(httpLinks, 1, 80fa7767c5Sopenharmony_ci DATA_GROUP(std::string("http://img.51miz.com/preview/sound/00/26/73/51miz-S267356-423D33372.mp3")), 81fa7767c5Sopenharmony_ci DATA_GROUP(std::string("https://img.51miz.com/preview/sound/00/26/73/51miz-S267356-423D33372.mp3"))); 82fa7767c5Sopenharmony_ci 83fa7767c5Sopenharmony_ci DATA_PROVIDER(hlsLinks, 1, 84fa7767c5Sopenharmony_ci DATA_GROUP(std::string("http://ngcdn001.cnr.cn/live/zgzs/index.m3u8")), 85fa7767c5Sopenharmony_ci DATA_GROUP(std::string("http://ls-open.qingting.fm/live/20500010/64k.m3u8?" 86fa7767c5Sopenharmony_ci "deviceid=00000000-0000-0000-0000-000000000000&format=aac")), 87fa7767c5Sopenharmony_ci DATA_GROUP(std::string("https://live.ximalaya.com/radio-first-page-app/live/1011/64.m3u8?transcode=aac"))); 88fa7767c5Sopenharmony_ci 89fa7767c5Sopenharmony_ci // @test(data="shortMusicUrls", tags=fast) 90fa7767c5Sopenharmony_ci PTEST((std::string url), Test single player play url music, and finished automatically) 91fa7767c5Sopenharmony_ci { 92fa7767c5Sopenharmony_ci std::unique_ptr<TestPlayer> player = TestPlayer::Create(); 93fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->SetSource(TestSource(url))); 94fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Prepare()); 95fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Play()); 96fa7767c5Sopenharmony_ci while (player->IsPlaying()) { 97fa7767c5Sopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(1000)); 98fa7767c5Sopenharmony_ci } 99fa7767c5Sopenharmony_ci } 100fa7767c5Sopenharmony_ci 101fa7767c5Sopenharmony_ci // @test(data="longMusicUrls", tags=fast) 102fa7767c5Sopenharmony_ci PTEST((std::string url), Test single player play url music, and finished manually) 103fa7767c5Sopenharmony_ci { 104fa7767c5Sopenharmony_ci std::unique_ptr<TestPlayer> player = TestPlayer::Create(); 105fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->SetSource(TestSource(url))); 106fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Prepare()); 107fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Play()); 108fa7767c5Sopenharmony_ci ASSERT_TRUE(player->IsPlaying()); 109fa7767c5Sopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(1000)); 110fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Stop()); 111fa7767c5Sopenharmony_ci } 112fa7767c5Sopenharmony_ci 113fa7767c5Sopenharmony_ci // @test(data="durationTestMusicUrls", tags=fast) 114fa7767c5Sopenharmony_ci PTEST((std::string url, int32_t expectDuration), Can get music duration) 115fa7767c5Sopenharmony_ci { 116fa7767c5Sopenharmony_ci std::unique_ptr<TestPlayer> player = TestPlayer::Create(); 117fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->SetSource(TestSource(url))); 118fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Prepare()); 119fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Play()); 120fa7767c5Sopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(1000)); 121fa7767c5Sopenharmony_ci int64_t duration; 122fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->GetDuration(duration)); 123fa7767c5Sopenharmony_ci ASSERT_TRUE(CheckTimeEquality(expectDuration, duration)); 124fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Stop()); 125fa7767c5Sopenharmony_ci } 126fa7767c5Sopenharmony_ci 127fa7767c5Sopenharmony_ci // @test(data="longMusicUrls", tags=fast) 128fa7767c5Sopenharmony_ci PTEST((std::string url), Can get current time) 129fa7767c5Sopenharmony_ci { 130fa7767c5Sopenharmony_ci int64_t currentMS {0}; 131fa7767c5Sopenharmony_ci std::unique_ptr<TestPlayer> player = TestPlayer::Create(); 132fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->SetSource(TestSource(url))); 133fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Prepare()); 134fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Play()); 135fa7767c5Sopenharmony_ci ASSERT_TRUE(player->IsPlaying()); 136fa7767c5Sopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(1000)); 137fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->GetCurrentTime(currentMS)); 138fa7767c5Sopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(1000)); 139fa7767c5Sopenharmony_ci ASSERT_TRUE(CheckTimeEquality(2000, currentMS)); 140fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Stop()); 141fa7767c5Sopenharmony_ci } 142fa7767c5Sopenharmony_ci 143fa7767c5Sopenharmony_ci // @test(data="longMusicUrls", tags=fast) 144fa7767c5Sopenharmony_ci PTEST((std::string url), Can seek to the position specified) 145fa7767c5Sopenharmony_ci { 146fa7767c5Sopenharmony_ci int64_t seekPos {5000}; 147fa7767c5Sopenharmony_ci int64_t currentMS {0}; 148fa7767c5Sopenharmony_ci std::unique_ptr<TestPlayer> player = TestPlayer::Create(); 149fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->SetSource(TestSource(url))); 150fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Prepare()); 151fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Play()); 152fa7767c5Sopenharmony_ci ASSERT_TRUE(player->IsPlaying()); 153fa7767c5Sopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(1000)); 154fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Seek(seekPos)); 155fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->GetCurrentTime(currentMS)); 156fa7767c5Sopenharmony_ci EXPECT_TRUE(CheckTimeEquality(seekPos, currentMS)); 157fa7767c5Sopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(2000)); 158fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Stop()); 159fa7767c5Sopenharmony_ci } 160fa7767c5Sopenharmony_ci 161fa7767c5Sopenharmony_ci // @test(data="longMusicUrls", tags=fast) 162fa7767c5Sopenharmony_ci PTEST((std::string url), Can seek after pause) 163fa7767c5Sopenharmony_ci { 164fa7767c5Sopenharmony_ci int64_t seekPos {5000}; 165fa7767c5Sopenharmony_ci int64_t currentMS {0}; 166fa7767c5Sopenharmony_ci std::unique_ptr<TestPlayer> player = TestPlayer::Create(); 167fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->SetSource(TestSource(url))); 168fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Prepare()); 169fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Play()); 170fa7767c5Sopenharmony_ci ASSERT_TRUE(player->IsPlaying()); 171fa7767c5Sopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(1000)); 172fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Pause()); 173fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Seek(seekPos)); 174fa7767c5Sopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(1000)); 175fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->GetCurrentTime(currentMS)); 176fa7767c5Sopenharmony_ci ASSERT_TRUE(CheckTimeEquality(seekPos, currentMS)); // pause + seek still pause 177fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Stop()); 178fa7767c5Sopenharmony_ci } 179fa7767c5Sopenharmony_ci 180fa7767c5Sopenharmony_ci // @test(data="longMusicUrls", tags=fast) 181fa7767c5Sopenharmony_ci PTEST((std::string url), Can pause, then seek, then play, final stop) 182fa7767c5Sopenharmony_ci { 183fa7767c5Sopenharmony_ci int64_t seekPos {5000}; 184fa7767c5Sopenharmony_ci int64_t currentMS {0}; 185fa7767c5Sopenharmony_ci std::unique_ptr<TestPlayer> player = TestPlayer::Create(); 186fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->SetSource(TestSource(url))); 187fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Prepare()); 188fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Play()); 189fa7767c5Sopenharmony_ci ASSERT_TRUE(player->IsPlaying()); 190fa7767c5Sopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(1000)); 191fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Pause()); 192fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Seek(seekPos)); 193fa7767c5Sopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(1000)); 194fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->GetCurrentTime(currentMS)); 195fa7767c5Sopenharmony_ci ASSERT_TRUE(CheckTimeEquality(seekPos, currentMS)); // pause + seek still pause 196fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Play()); 197fa7767c5Sopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(2000)); // pause + seek + play still play 198fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Stop()); 199fa7767c5Sopenharmony_ci } 200fa7767c5Sopenharmony_ci 201fa7767c5Sopenharmony_ci // @test(data="longMusicUrls", tags=fast) 202fa7767c5Sopenharmony_ci PTEST((std::string url), Can play after pause) 203fa7767c5Sopenharmony_ci { 204fa7767c5Sopenharmony_ci std::unique_ptr<TestPlayer> player = TestPlayer::Create(); 205fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->SetSource(TestSource(url))); 206fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Prepare()); 207fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Play()); 208fa7767c5Sopenharmony_ci ASSERT_TRUE(player->IsPlaying()); 209fa7767c5Sopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(1000)); 210fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Pause()); 211fa7767c5Sopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(1000)); 212fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Play()); 213fa7767c5Sopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(1000)); 214fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Stop()); 215fa7767c5Sopenharmony_ci } 216fa7767c5Sopenharmony_ci 217fa7767c5Sopenharmony_ci // @test(data="shortMusicUrls", tags=fast) 218fa7767c5Sopenharmony_ci PTEST((std::string url), Can single Loop) 219fa7767c5Sopenharmony_ci { 220fa7767c5Sopenharmony_ci std::unique_ptr<TestPlayer> player = TestPlayer::Create(); 221fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->SetSource(TestSource(url))); 222fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->SetSingleLoop(true)); 223fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Prepare()); 224fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Play()); 225fa7767c5Sopenharmony_ci std::this_thread::sleep_for(std::chrono::seconds(20)); 226fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Stop()); 227fa7767c5Sopenharmony_ci } 228fa7767c5Sopenharmony_ci 229fa7767c5Sopenharmony_ci // @test(data="httpLinks", tags=http) 230fa7767c5Sopenharmony_ci PTEST((std::string url), Test http audio play) 231fa7767c5Sopenharmony_ci { 232fa7767c5Sopenharmony_ci std::unique_ptr<TestPlayer> player = TestPlayer::Create(); 233fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->SetSource(TestSource(url))); 234fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Prepare()); 235fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Play()); 236fa7767c5Sopenharmony_ci std::this_thread::sleep_for(std::chrono::seconds(20)); 237fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Seek(10000)); 238fa7767c5Sopenharmony_ci std::this_thread::sleep_for(std::chrono::seconds(10)); 239fa7767c5Sopenharmony_ci player->Stop(); 240fa7767c5Sopenharmony_ci } 241fa7767c5Sopenharmony_ci 242fa7767c5Sopenharmony_ci // @test(data="hlsLinks", tags=http) 243fa7767c5Sopenharmony_ci PTEST((std::string url), Test hls audio broadcast) 244fa7767c5Sopenharmony_ci { 245fa7767c5Sopenharmony_ci std::unique_ptr<TestPlayer> player = TestPlayer::Create(); 246fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->SetSource(TestSource(url))); 247fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Prepare()); 248fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Play()); 249fa7767c5Sopenharmony_ci std::this_thread::sleep_for(std::chrono::seconds(20)); 250fa7767c5Sopenharmony_ci player->Stop(); 251fa7767c5Sopenharmony_ci } 252fa7767c5Sopenharmony_ci 253fa7767c5Sopenharmony_ci // @test(data="FileFdSourceTestShortMusicUrls", tags=fast) 254fa7767c5Sopenharmony_ci PTEST((std::string url, int32_t fileSize), Can fd play single Loop) 255fa7767c5Sopenharmony_ci { 256fa7767c5Sopenharmony_ci std::string uri = "fd://?offset=0&size="; 257fa7767c5Sopenharmony_ci uri += std::to_string(fileSize); 258fa7767c5Sopenharmony_ci int32_t fd = open(url.c_str(), O_RDONLY|O_BINARY); 259fa7767c5Sopenharmony_ci std::string fdStr = std::to_string(fd); 260fa7767c5Sopenharmony_ci uri.insert(5, fdStr); 261fa7767c5Sopenharmony_ci std::unique_ptr<TestPlayer> player = TestPlayer::Create(); 262fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->SetSource(TestSource(uri))); 263fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->SetSingleLoop(true)); 264fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Prepare()); 265fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Play()); 266fa7767c5Sopenharmony_ci std::this_thread::sleep_for(std::chrono::seconds(20)); 267fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Stop()); 268fa7767c5Sopenharmony_ci } 269fa7767c5Sopenharmony_ci 270fa7767c5Sopenharmony_ci // SUB_MEDIA_PLAYER_LOCAL_AUDIO_FUNCTION_LOOP 271fa7767c5Sopenharmony_ci // @test(data="durationTestMusicUrls", tags=fast) 272fa7767c5Sopenharmony_ci PTEST((std::string url, int32_t expectDuration), Seek to the location of the file near the end) 273fa7767c5Sopenharmony_ci { 274fa7767c5Sopenharmony_ci std::unique_ptr<TestPlayer> player = TestPlayer::Create(); 275fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->SetSource(TestSource(url))); 276fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Prepare()); 277fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Play()); 278fa7767c5Sopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(1000)); 279fa7767c5Sopenharmony_ci int64_t duration; 280fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->GetDuration(duration)); 281fa7767c5Sopenharmony_ci ASSERT_TRUE(CheckTimeEquality(expectDuration, duration)); 282fa7767c5Sopenharmony_ci int32_t count = 5; 283fa7767c5Sopenharmony_ci while (count > 0) { 284fa7767c5Sopenharmony_ci NZERO_LOG(player->Seek(duration - 100)); 285fa7767c5Sopenharmony_ci NZERO_LOG(player->Seek(0)); 286fa7767c5Sopenharmony_ci count--; 287fa7767c5Sopenharmony_ci } 288fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Reset()); 289fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Release()); 290fa7767c5Sopenharmony_ci } 291fa7767c5Sopenharmony_ci 292fa7767c5Sopenharmony_ci // @test(data="shortMusicUrls", tags=fast) 293fa7767c5Sopenharmony_ci PTEST((std::string url), Test play finished can play again) 294fa7767c5Sopenharmony_ci { 295fa7767c5Sopenharmony_ci std::unique_ptr<TestPlayer> player = TestPlayer::Create(); 296fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->SetSource(TestSource(url))); 297fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Prepare()); 298fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Play()); 299fa7767c5Sopenharmony_ci while (player->IsPlaying()) { 300fa7767c5Sopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(1000)); 301fa7767c5Sopenharmony_ci } 302fa7767c5Sopenharmony_ci ASSERT_EQ(0, player->Play()); 303fa7767c5Sopenharmony_ci while (player->IsPlaying()) { 304fa7767c5Sopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(1000)); 305fa7767c5Sopenharmony_ci } 306fa7767c5Sopenharmony_ci } 307fa7767c5Sopenharmony_ci}; 308