| 53 | } |
| 54 | |
| 55 | drmp3_bool32 seekCallback(void* userData, int offset, drmp3_seek_origin origin) |
| 56 | { |
| 57 | auto* stream = static_cast<sf::InputStream*>(userData); |
| 58 | |
| 59 | if (origin == DRMP3_SEEK_CUR) |
| 60 | { |
| 61 | auto currentPosition = stream->tell(); |
| 62 | |
| 63 | if (!currentPosition.has_value()) |
| 64 | return false; |
| 65 | |
| 66 | offset = static_cast<int>(currentPosition.value()) + offset; |
| 67 | } |
| 68 | else if (origin == DRMP3_SEEK_END) |
| 69 | { |
| 70 | auto currentSize = stream->getSize(); |
| 71 | |
| 72 | if (!currentSize.has_value()) |
| 73 | return false; |
| 74 | |
| 75 | offset = static_cast<int>(currentSize.value()) + offset; |
| 76 | } |
| 77 | |
| 78 | const std::optional position = stream->seek(static_cast<std::size_t>(offset)); |
| 79 | return position.has_value(); |
| 80 | } |
| 81 | |
| 82 | drmp3_bool32 tellCallback(void* userData, drmp3_int64* pCursor) |
| 83 | { |